Skip to content

Commit

Permalink
Added expire_user_access_tokens util method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhay Tea authored and Chhay Tea committed Feb 2, 2017
1 parent ef9fda4 commit b3b0d47
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions provider/oauth2/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from datetime import timedelta

from django.utils.timezone import now

from ..constants import DEFAULT_SCOPES
from ..scope import to_names
from .models import Client
Expand All @@ -24,3 +28,10 @@ def create_access_and_refresh_token(client, user, scope=None):
'expires_at': access_token.expires_text,
'scope': ' '.join(to_names(access_token.scope)),
}


def expire_user_access_tokens(user):
"""Expire all active tokens associated with a user"""
current_ts = now()
expire_ts = current_ts - timedelta(minutes=1)
AccessToken.objects.filter(user=user, expires__gte=current_ts).update(expires=expire_ts)

0 comments on commit b3b0d47

Please sign in to comment.