Add scope ordinality and translations. Process oauth tokens and limit scopes accordingly.
This commit is contained in:
parent
25ceb90fc6
commit
e74eb3ee87
8 changed files with 137 additions and 31 deletions
|
@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
|||
from oauth2lib.provider import AuthorizationProvider
|
||||
from oauth2lib import utils
|
||||
|
||||
from data.database import OAuthApplication, OAuthAuthorizationCode, OAuthAccessToken
|
||||
from data.database import OAuthApplication, OAuthAuthorizationCode, OAuthAccessToken, User
|
||||
from auth import scopes
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ class DatabaseAuthorizationProvider(AuthorizationProvider):
|
|||
return False
|
||||
|
||||
def validate_scope(self, client_id, scope):
|
||||
return scope in scopes.ALL_SCOPES.keys()
|
||||
return scopes.validate_scope_string(scope)
|
||||
|
||||
def validate_access(self):
|
||||
return self.get_authorized_user() is not None
|
||||
|
@ -140,3 +140,14 @@ class DatabaseAuthorizationProvider(AuthorizationProvider):
|
|||
|
||||
def create_application(org, redirect_uri, **kwargs):
|
||||
return OAuthApplication.create(organization=org, redirect_uri=redirect_uri, **kwargs)
|
||||
|
||||
def validate_access_token(access_token):
|
||||
try:
|
||||
found = (OAuthAccessToken
|
||||
.select(OAuthAccessToken, User)
|
||||
.join(User)
|
||||
.where(OAuthAccessToken.access_token == access_token)
|
||||
.get())
|
||||
return found
|
||||
except OAuthAccessToken.DoesNotExist:
|
||||
return None
|
Reference in a new issue