-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: implement RFC 8628 #3912
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
feat: implement RFC 8628 #3912
Conversation
baaef03 to
469c5e1
Compare
469c5e1 to
7970287
Compare
7970287 to
8790af4
Compare
8790af4 to
14cf7cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I'll push some minor changes from my side and left a couple of comments.
I primarily cleaned up error handling to make it standards compliant
persistence/sql/migrations/20241609000001000000_device_flow.cockroach.up.sql
Outdated
Show resolved
Hide resolved
0a4fa13 to
2e8cf7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments, but I think we're getting quite close. Preventing replay attacks definitely needs to be addressed before merge
persistence/sql/migrations/20241609000001000000_device_flow.cockroach.up.sql
Outdated
Show resolved
Hide resolved
persistence/sql/src/YYYYMMDD000001_device_flow/20241609000001000000_device_flow.mysql.up.sql
Outdated
Show resolved
Hide resolved
9e2e241 to
d338178
Compare
|
Let me know when this is good for another review |
|
@aeneasr sorry for the late response, everything should be good for another review now. |
73b187d to
9c81f0f
Compare
|
I tried performing the flow using the included CLI tooling, but it failed with this:
|
|
Or does device auth always use post form submit? From looking at the go oauth2 library it appears to be the case? |
|
Would it be possible to get ory/hydra-login-consent-node#123 ready to merge so that the quickstart can be used for the device auth code flow? :) |
|
I've fixed up the node PR: ory/hydra-login-consent-node#161 And made the CLI changes.
Otherwise it seems like everything is working! I was able to perform the device auth code flow end to end :) ps: the node pr includes a pre-release of the SDK that has the device auth code flow methods included |
|
One last thing we need is some docs. I was thinking a dedicated page for this grant type:
@christiannwamba anything I missed? |
It is a little bit weird. I think there was a discussion around this in the original PR as well, but I can't fine it right now. RFC section 3.1 says:
Reading this, I understand that the client must authenticate when making the device authz request. But the golang oauth2 lib does not provide client authentication in that request. There is an open issue about it golang/oauth2#685, that hasn't been addressed for quite some time. My guess is that most people will use public clients for the device flow and that's why they don't care. I think that some of the public providers don't require client authn for this request either, so I was conflicted about whether I should add it or not. We could make the CLI work by patching the http client used to add the basic auth header, I agree that this would provide better UX. I will give it a shot. |
I think that covers it. Should go under the guides section. |
It‘s fine - the device flow should actually only use public clients as end devices can‘t keep secrets. I confirmed that this works. |
|
What I did:
What I found and what I believe needs to be addressed:
|
|
Looks like I messed up the tests - very sorry about that! I‘m currently PTO but trying to squeeze it in :) |
Nw, I will try to fix them |
Not implementing the reject endpoint was part of the plan. I thought that it could be added at a later time if needed. The
It should be tested by https://github.com/nsklikas/hydra/blob/canonical-master/oauth2/oauth2_device_code_test.go#L624
Good catch, removed
I thought that the tables are cleaned asynchronously by hydra janitor. Am I missing something? The janitor work was supposed to be handled on a different PR.
That's correct, will update the schema
It shouldn't be possible to do that, if you were able to get a
AFAICT the device flow is not supported by the
Good point, I will redact it.
Great point, I will create
Right, will add it |
5ec978d to
3541e40
Compare
3277d14 to
1e55e05
Compare
1e55e05 to
ee0738f
Compare
|
To test: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a mountain of work. Thank you @nsklikas, @supercairos and @BuzzBumbleBee. I know it took way longer than you probably have ever thought, but I am very glad that Canonical stepped up and did not give up on this huge project. The result is truly amazing and I am very happy to approve and merge this PR. I will do one last last last round of sanity checks but the great collaboration in recent weeks gives me a ton of confidence that we have solved this huge challenge extremely well. Thank you everyoneryone, again!
|
Ok, the latest changes make sense. Let's do it :) |
|
wonderful job everyone ❤️ @aeneasr when can we expect a github release? 🙏 |
| deviceChallenge | ||
| deviceVerifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsklikas injecting those here breaks the existing ENUM. This should really be appended - unfortunately I missed this during review, but for future reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shit, sorry I didn't think of that. Thanks for pointing it out, will try to be mindful of this in the future.
This patch introduces the OAuth 2.0 Device Authorization Grant to Ory Hydra. The OAuth 2.0 device authorization grant is designed for Internet-connected devices that either lack a browser to perform a user-agent-based authorization or are input constrained to the extent that requiring the user to input text in order to authenticate during the authorization flow is impractical. It enables OAuth clients on such devices (like smart TVs, media consoles, digital picture frames, and printers) to obtain user authorization to access protected resources by using a user agent on a separate device.
The OAuth 2.0 Device Authorization Grant may also become relevant for AI Agent authentication flows and is generally an amazing step and innovation for this project.
A very special thanks goes to @nsklikas from Canonical, @supercairos from shadow.tech and @BuzzBumbleBee.
For more details, please check out the documentation (ory/docs#2026)
To implement this feature, you will need to implement two additional screens in your login and consent application. A reference implementation can be found here.
Closes #3851
Closes #3252
Closes #3230
Closes #2416
This PR is a continuation of #3851. I have created it from my own personal repo and I have invited people from Ory to contribute so that we can speed up things. I think that most of the comments in the old PR were resolved, but I can copy them to this PR if we wish to keep the discussion history.
Implements the Device Authorization Grant to enable authentication for headless machines (see https://datatracker.ietf.org/doc/html/rfc8628)
Related issue(s)
Implements RFC 8628.
This PR is based on the work done on #3252, by @supercairos and @BuzzBumbleBee. That PR was based on an older version of Hydra and was missing some features/tests.
We have prepared a spec, that describes our design and implementation. We have tried to mimic the existing logic in Hydra and not make changes that would disrupt the existing workflows
Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further Comments
Notes:
memoryandpostgresdatabases. The tests pass all of them.go.mod.Testing
To test this you need to built the hydra image:
make dockerThis will create an image with the name:
oryd/hydra:latest-sqliteTo run the flow you can use our UI, from https://github.com/canonical/identity-platform-login-ui/tree/hydra-device-test:
Create a client for Hydra:
docker exec -it identity-platform-login-ui-hydra-1 hydra create client --endpoint http://localhost:4445 --grant-type authorization_code,refresh_token,urn:ietf:params:oauth:grant-type:device_code --scope openid,offline_access,email,profile --token-endpoint-auth-method client_secret_postUse that client to perform the device flow:
docker exec -it identity-platform-login-ui-hydra-1 hydra perform device-code --client-id <client-id> --client-secret <client-secret> -e http://localhost:4444 --scope openid,offline_access,email,profileThe user for logging in is:
[email protected]test