-
Notifications
You must be signed in to change notification settings - Fork 10
Feat/authz #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/authz #28
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #9 and #10
Pubky Auth
This PR defines an authentication/authorization system proposed for Pubky, allowing 3rd party apps to request authorization to access some resources on the user's Homeserver.
glossary
Flow
3rd Party App
generates a unique (32 bytes)cleint_secret
.3rd Party App
uses thebase64url(hash(client_secret))
as achannlen_id
and subscribe to that channel on theHTTP Relay
it is using.3rd Party App
formats a Pubky Auth urlfor example
and finally show that URL as a QR code to the user.
4. The
Authenticator
app scans that QR code, parse the URL, and show a consent form for the user..5. The user decides whether or not to grant these capabilities to the
3rd Party App
.6. If the user approves, the
Authenticator
then uses their Keypair, to sign an AuthToken, then encrypt that token with theclient_secret
, then calculate thechannel_id
by hashing that secret, and send that encrypted token to the callback url, which is therelay
+channel_id
.7.
HTTP Relay
forwards the encrypted AuthToken to the3rd Party App
frontend.8. And confirms the delivery with the
Authenticator
9.
3rd Party App
decrypts the AuthToken using itsclient_secret
, read thepubky
in it, and send it to theirhomeserver
to obtain a session.10.
Homeserver
verifies the session and stores the correspondingcapabilities
.11.
Homeserver
returns a session Id to the frontend to use in subsequent requests.12.
3rd Party App
uses the session Id to access some resource at the Homeserver.13.
Homeserver
checks the session capabilities to see if it is allowed to access that resource.14.
Homeserver
responds to the3rd Party App
with the resource.AuthToken encoding
AuthToken verification
To verify a token, the
homeserver
should:0
for this spec.timestamp
is within a window from the local time, the default should be 45 seconds in the past, and 45 seconds in the future to handle latency and drifts.pubky
is the signer of thesignature
over the rest of the serialized token after the signature (serialized_token[65..]
).homeserver
should consider thetimestamp
andpubky
(serialized_token[75..115]
) as a unique sortable ID, and store it in a sortable key value store, rejecting any token that has that same ID, and removing all IDs that start with a timestamp that is older than the window mentioned in step 4.Unhosted
Callback URLs work fine for full-stack applications, but there are many cases where you would want to develop and application without a backend, yet you still would like to let users sign in and bring their own backend, that is not a new concept, in fact unhosted applications is one of the main reasons we are developing Homeservers.
These applications will still need some relay to receive the
AuthToken
through when theAuthenticator
sends it to the callback URL, but since theAuthToken
is a bearer token, these relays can intercept it and use it before the unhosted app.That is why we need to encrypt the
AuthToken
with a key that the relay doesn't have access to, and only shared between the app and theAuthenticator
Limitations
No delegation
In version zero, the
pubky
IS theissuer
, meaning that theAuthToken
is signed by the same key of thepubky
. This is to simplify the spec, until we have a reason to keep theissuer
keys even more secure than being in a mobile app used rarely to authenticate a browser session once in a while.Having an
issuer
that isn't exactly thepubky
means theissuer
themselves need a certificate of delegation signed by thepubky
. The problem with that, is that you can either lookup that certificate on the Homeserver (making the verification process async and possibly taking too long to timeout) or do what most TLS apps do right now, and send the certificates chain with the token, but then you have to deal with the eternal problem of revocation, which basically also forces you to go lookup somewhere making the the verification process async and possibly taking too long to timeout.Expiration is out of scope
While the token itself can only be used for very brief period, it is immediately exchanged for another authentication mechanism (usually a session ID) and deciding the expiration date of that authentication, if any, is out of the scope of this spec.
The assumption here is that we are authorizing a session to the Homeserver, so the user can always access all active sessions and revoke any session that they don't like, from the
Authenticator
app.Other services are free to choose their authentication system once the homeserver verifies the pubky auth token, whether that is a JWT or a Session with or without expiration and are free to allow the user to manage sessions the way they see fit.