Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access token from view

I am starting with django-rest-framework and I can't find the way to access the Token value from the view, is it possible? I am not using built-in token generator, I use a custom function to do it. In request's headers I give this:

Authorization: 'Token kjansfd98qhr23d09823098fdj'

How can I access that value in the view? Or maybe there's a best way to work with custom tokens.

PD: I am not using Django's default User model.

like image 639
Gocht Avatar asked Aug 04 '15 15:08

Gocht


People also ask

How do I find my access token?

The high-level overview of validating an access token looks like this: Retrieve and parse your Okta JSON Web Keys (JWK), which should be checked periodically and cached by your application. Decode the access token, which is in JSON Web Token format. Verify the signature used to sign the access token.

Is access token same as JWT token?

The OAuth access token is different from the JWT in the sense that it's an opaque token. The access token's purpose is so that the client application can query Google to ask for more information about the signed in user. email: The end user's email ID.

How can I get access token from JWT token?

Obtain the access token To request an access token, send a POST request containing the JWT to the DocuSign authentication service. The response to a successful request will include your access token value.


1 Answers

You can access them within a view using request.META, which is a dictionary. So you can use request.META.get('HTTP_AUTHORIZATION') to access autherizatoin token.

For more details visit Django TokenAuthentication missing the 'Authorization' http header

If you are deploying to Apache, and using any non-session based authentication, you will need to explicitly configure mod_wsgi to pass the required headers through to the application. This can be done by specifying the WSGIPassAuthorization directive in the appropriate context and setting it to 'On'. For details please visit http://www.django-rest-framework.org/api-guide/authentication/

like image 152
Rajesh Kaushik Avatar answered Oct 06 '22 20:10

Rajesh Kaushik