Comments (8)
@masci Not sure whether this is the approach you were considering but one very simple way to give protected views access to the user associated with the token would be via
--- a/oauth2_provider/views/mixins.py
+++ b/oauth2_provider/views/mixins.py
@@ -165,6 +165,7 @@ class ProtectedResourceMixin(OAuthLibMixin):
def dispatch(self, request, *args, **kwargs):
valid, r = self.verify_request(request)
if valid:
+ request.resource_owner = r.user
return super(ProtectedResourceMixin, self).dispatch(request, *args, **kwargs)
else:
return HttpResponseForbidden()
request.resource_owner
might be better than request.user
as to differentiate the two although they should likely never both be available simultaneously.
Looking forward to playing around more with django-oauth-toolkit soon, gone over the installation which was a breeze. Nice work =)
from django-oauth-toolkit.
Hi João,
the request object you encounter in oauth2_validators.py module is not a Django request, think about it as an object belonging to the oauthlib world, which is "framework-agnostic".
APIs endpoint protected with django-oauth-toolkit are supposed to be accessed without logging in the user (that's where OAuth comes into play) providing an access token instead.
Trying to answer your question: at the moment Django OAuth Toolkit does not provide a simple way to retrieve the user whom the access token belongs to, you have to make a query for that.
If you post your use case we could discuss this and trying to provide a solution.
from django-oauth-toolkit.
@ib-lundgren Neat!
This way we also avoid an additional query to retrieve the user instance.
Also 'resource_owner' could be appropriate since it is clear that it's Oauth stuff.
Good to me 👍
Looking forward to playing around more with django-oauth-toolkit soon, gone over the installation which was a breeze. Nice work =)
Thank you
from django-oauth-toolkit.
@ib-lundgren thanks, that makes sense to me. Trying it out
I'm an oAuth2 newbie, so don't assume I know what I'm talking about. I feel that request.user should not be AnonymousUser, but the "correct" approach would be to be the application which is the user and not the resource owner (as all of you have pointed out). django-auth-toolkit doesn't allow this now and I don't need it, I just want to know if I'm thinking along the right lines.
Thanks,
João
from django-oauth-toolkit.
Just to note that @ib-lundgren's solution works well for me and I'd love to see the patch integrated. Is a PR needed?
from django-oauth-toolkit.
Yes, please! :-)
from django-oauth-toolkit.
@jneves a PR would be great!
Please read contributing guidelines before submitting.
from django-oauth-toolkit.
@masci @synasius thanks, done.
from django-oauth-toolkit.
Related Issues (20)
- invalid_client when no Client Secret sent for PKCE HOT 1
- /token not returning the new refresh token HOT 1
- What is the release cadence? HOT 2
- { "error": "invalid_grant", "error_description": "Invalid credentials given." } HOT 1
- Refresh ID token help HOT 1
- `OAuth2Authentication` without DRF's `BaseAuthentication` inheritance HOT 1
- Refresh token reuse detection HOT 1
- Error uploading a raw file with the DRF HOT 5
- ModuleNotFoundError: No module named 'oauth2_providerapi' HOT 1
- Support for optional Authorization Server Metadata HOT 1
- Remove 255 Character Limit on Tokens to Support JWT with Additional Claims HOT 7
- Custom validator not being called HOT 1
- Generate token after autorization HOT 1
- Add `localhost` to Allowed Loopback Addresses for Redirect URIs HOT 1
- Suitability for LTI 1.3 HOT 1
- Introspect returns 200 when access token does not exist HOT 3
- Django axes with msal integration
- Missing Import in Documentation HOT 3
- app without client_secret (still) not working? HOT 3
- ValueError in jwks.json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-oauth-toolkit.