简体   繁体   中英

How do i pass extra context from DRF Custom authentication class

I am using DRF for building an API in django. I have written a custom authentication class based on rest_framework.authentication.BaseAuthentication , that validates a incoming JWT. Within the JWT payload i have an attribute, say "organisation_id":"123" , which i would like to access in the view that processes the request. Is there any possibility to add the attribute to the context of the request object? According to the DRF docs , the authenticate method of the BaseAuthentication should only return the tuple (user, auth) .

As far as I can tell, you already have the request as an argument to the authentication function. You should be able to add your organisation_id to the request:

request.organisation_id = organisation_id

This should do although I would personally rather go with adding it to the user.

Your call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM