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
How to get user object via access_token? #140
Comments
I have the same question. |
It depends on what you have access to in the current scope. If you're in the code of an authenticated view, your user has already been determined by django and the jwt plugin. You'd do something like this: def my_view(request):
request.user If all you have is the base64 encoded access token string, you can decode it using the from restframework_simplejwt.tokens import AccessToken
token_str = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU'
access_token = AccessToken(token_str)
user = User.objects.get(access_token['user_id']) |
|
@xianfuxing How come the authentication framework isn't giving you a user object on the request? |
Can I get the user object via access token?
The text was updated successfully, but these errors were encountered: