Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check expiration of token #218

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rest_framework_social_oauth2/oauth2_grants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time

try:
from django.urls import reverse
Expand Down Expand Up @@ -90,6 +91,11 @@ def validate_token_request(self, request):

try:
user = backend.do_auth(access_token=request.token)
user_data = backend.user_data(access_token=request.token)
exp = user_data['exp']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the value exp holds?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exp is the expiration date of the token

if exp is not None and exp <= int(time.time()):
paulw11 marked this conversation as resolved.
Show resolved Hide resolved
raise errors.InvalidTokenError('Token has expired', request=request)

except requests.HTTPError as e:
raise errors.InvalidRequestError(
description="Backend responded with HTTP{0}: {1}.".format(e.response.status_code,
Expand Down