-
Notifications
You must be signed in to change notification settings - Fork 819
Description
My project has a requirement to set the token expiration per some auth cookie validity (means the token expiration is not static, but variable per token been issued. The token expiration is result of some method instead of static oauth2_settings.ACCESS_TOKEN_EXPIRE_SECONDS).
The oauthlib Server init function accepts both static value or callable function as an input:
class Server(AuthorizationEndpoint, TokenEndpoint, ResourceEndpoint,
RevocationEndpoint):
def __init__(self, request_validator, token_expires_in=None,
token_generator=None, refresh_token_generator=None,
*args, **kwargs):
The oauthlib tokens.py BearerToken class has its own default expiration value set: self.expires_in = expires_in or 3600
class BearerToken(TokenBase):
....
def __init__(self, request_validator=None, token_generator=None,
expires_in=None, refresh_token_generator=None):
....
self.expires_in = expires_in or 3600
Unfortunately token_expires_in is ignored by DOT. The token expiration seems to be hardcoded into the save_bearer_token in oauth2_validators.py.
@transaction.atomic
def save_bearer_token(self, token, request, *args, **kwargs):
....
expires = timezone.now() + timedelta(seconds=oauth2_settings.ACCESS_TOKEN_EXPIRE_SECONDS)
and
# TODO: check out a more reliable way to communicate expire time to oauthlib
token['expires_in'] = oauth2_settings.ACCESS_TOKEN_EXPIRE_SECONDS
I think that better implementation would be to explicitly pass the oauth2_settings.ACCESS_TOKEN_EXPIRE_SECONDS as token_expires_in value and respect token['expires_in'] in save_bearer_token().