Add ability for users to see their authorized applications and revoke the access

This commit is contained in:
Joseph Schorr 2014-03-24 20:57:02 -04:00
parent e92cf37583
commit c82d1ffe98
10 changed files with 262 additions and 3 deletions

View file

@ -221,6 +221,26 @@ def delete_application(org, client_id):
application.delete_instance(recursive=True, delete_nullable=True)
return application
def lookup_access_token_for_user(user, token_uuid):
try:
return OAuthAccessToken.get(OAuthAccessToken.authorized_user == user,
OAuthAccessToken.uuid == token_uuid)
except OAuthAccessToken.DoesNotExist:
return None
def list_access_tokens_for_user(user):
query = (OAuthAccessToken
.select()
.join(OAuthApplication)
.switch(OAuthAccessToken)
.join(User)
.where(OAuthAccessToken.authorized_user == user))
return query
def list_applications_for_org(org):
query = (OAuthApplication
.select()
@ -228,3 +248,11 @@ def list_applications_for_org(org):
.where(OAuthApplication.organization == org))
return query
def create_access_token_for_testing(user, client_id, scope):
expires_at = datetime.now() + timedelta(seconds=10000)
application = get_application_for_client_id(client_id)
OAuthAccessToken.create(application=application, authorized_user=user, scope=scope,
token_type='token', access_token='test',
expires_at=expires_at, refresh_token='', data='')