Selaa lähdekoodia

[Fix] OAuth2 Token validation (#3694)

Convert token expiration time to utc and compare with utcnow
version-14
Revant Nandgaonkar 8 vuotta sitten
committed by Rushabh Mehta
vanhempi
commit
9fb5839f5c
1 muutettua tiedostoa jossa 5 lisäystä ja 2 poistoa
  1. +5
    -2
      frappe/oauth.py

+ 5
- 2
frappe/oauth.py Näytä tiedosto

@@ -1,5 +1,6 @@
from __future__ import print_function from __future__ import print_function
import frappe, urllib import frappe, urllib
import pytz


from frappe import _ from frappe import _
from urlparse import parse_qs, urlparse from urlparse import parse_qs, urlparse
@@ -227,8 +228,10 @@ class OAuthWebRequestValidator(RequestValidator):


def validate_bearer_token(self, token, scopes, request): def validate_bearer_token(self, token, scopes, request):
# Remember to check expiration and scope membership # Remember to check expiration and scope membership
otoken = frappe.get_doc("OAuth Bearer Token", token) #{"access_token": str(token)})
is_token_valid = (frappe.utils.datetime.datetime.now() < otoken.expiration_time) \
otoken = frappe.get_doc("OAuth Bearer Token", token)
token_expiration_local = otoken.expiration_time.replace(tzinfo=pytz.timezone(frappe.utils.get_time_zone()))
token_expiration_utc = token_expiration_local.astimezone(pytz.utc)
is_token_valid = (frappe.utils.datetime.datetime.utcnow().replace(tzinfo=pytz.utc) < token_expiration_utc) \
and otoken.status != "Revoked" and otoken.status != "Revoked"
client_scopes = frappe.db.get_value("OAuth Client", otoken.client, 'scopes').split(get_url_delimiter()) client_scopes = frappe.db.get_value("OAuth Client", otoken.client, 'scopes').split(get_url_delimiter())
are_scopes_valid = True are_scopes_valid = True


Ladataan…
Peruuta
Tallenna