-
-
Notifications
You must be signed in to change notification settings - Fork 493
Device flow: Pass verification_uri_complete to endpoint + pass Server kwargs to DeviceCodeGrant to allow validators to be setup with more flexibility #891
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
Conversation
535b12f
to
d230a05
Compare
8fc44dd
to
3a25fd0
Compare
Needed as a caller is unable to tell the device endpoint to return the verification_uri_complete value
3a25fd0
to
460ae31
Compare
hmm why is ruff reporting on lines unrelated to my change? |
bb9ec29
to
b0503f8
Compare
In order for the device grant's pre token custom valisator to run as the parent class "GrantTypeBase" sets it up like def _setup_custom_validators(self, kwargs): post_auth = kwargs.get('post_auth', []) post_token = kwargs.get('post_token', []) pre_auth = kwargs.get('pre_auth', []) pre_token = kwargs.get('pre_token', []) The need for this was discovered because a pre_token callable needs to be passed in order to set oauthlib's request.user attribute accordingly before the token gets saved
b0503f8
to
ca06e96
Compare
@auvipy doesn't let me add reviewers so tagging |
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.
shouldn't we also update relevant docs?
@auvipy it's already documented :) oauthlib/docs/oauth2/endpoints/device.rst Line 47 in 028c563
edit: let me update this line here actually as well oauthlib/docs/oauth2/endpoints/device.rst Line 30 in 028c563
|
Note to reviewer: pr is best reviewed commit by commit
While implementing this
I realised two things are missing
verification_uri_complete
isn't being passed to the endpointExplanation of 2:
oauthlib assumes code like so for adding custom validators (or rather, examples in the code base do this but the constructor of a grant allows for generic kwargs to be passed in to set it up)
However there are cases where one would want more flexibility. What do I mean flexibility? All grant's inherit from
GrantTypeBase
and have a constructor like:One might want to pass in any combination of the custom validators to the
Server
that uses the Grant object as a generic dict of server kwargs (like is done in django-oauth-toolkit in order to abstract oauthlib away)By allowing this it makes it easier to set up the validator checks
But what were you even trying to do in the first place?
For the device code this means being able to pass in a validation callable in a more flexible manner to assign
oauthlib.common.Request's
user attribute before the access token is made and saved allowing to associate the device user with the access token userScreenshot showing access tokens having users set from the device flow and


verification_uri_complete
(https://datatracker.ietf.org/doc/html/rfc8628#section-3.2) coming back from the authorization stage