jazzband / django-oauth-toolkit

OAuth2 goodies for the Djangonauts!
https://django-oauth-toolkit.readthedocs.io
Other
3.13k stars 792 forks source link

Custom ACCESS_TOKEN_EXPIRE_SECONDS by application #650

Closed tximpa91 closed 11 months ago

tximpa91 commented 5 years ago

Hi,

I think that my question is pretty straight forward. I want to change the access_token_expire_secondsby application_id something custom like scopes classes.

Kind Regards.

jleclanche commented 5 years ago

https://github.com/jazzband/django-oauth-toolkit/blob/ee8cb080ff13b3fad8fd68a47ae7d5a671222a2c/oauth2_provider/oauth2_validators.py#L456

I don't think it's possible right now.

jywsn commented 4 years ago

I think you could write a custom validator, subclassing oauth2_provider.oauth2_validators.OAuth2Validator and overriding the save_bearer_token() method. Within this method, you know the request.client.

dopry commented 11 months ago

overriding the validator should work. I would be open to a PR that introduces token settings at the application level it should defer the expires value to the Application model like validate_redirect_uri with something like

expires = request.client.get_access_token_lifetime()

and the application model should be update with an access token lifetime. It would be good to do bearer tokens as well.