Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
token/get_scope endpoint. Fixes #158
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Feb 5, 2016
1 parent db777be commit 9c049d2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lastuser_oauth/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,47 @@ def token_verify():
return api_result('ok', **params)


@csrf.exempt
@lastuser_oauth.route('/api/1/token/get_scope', methods=['POST'])
@requires_client_login
def token_get_scope():
token = request.form.get('access_token')
if not token:
# No token specified by caller
return resource_error('no_token')

authtoken = AuthToken.get(token=token)
if not authtoken:
# No such auth token
return api_result('error', error='no_token')

client_resources = []
nsprefix = g.client.namespace + ':'
for item in authtoken.scope:
if item.startswith(nsprefix):
client_resources.append(item[len(nsprefix):])

if not client_resources:
return api_result('error', error='no_access')

# All validations passed. Token is valid for this client. Return with information on the token
# TODO: Don't return validity. Set the HTTP cache headers instead.
params = {'validity': 120} # Period (in seconds) for which this assertion may be cached.
if authtoken.user:
params['userinfo'] = get_userinfo(authtoken.user, g.client, scope=authtoken.scope)
params['clientinfo'] = {
'title': authtoken.client.title,
'userid': authtoken.client.owner.userid,
'buid': authtoken.client.owner.userid,
'owner_title': authtoken.client.owner.pickername,
'website': authtoken.client.website,
'key': authtoken.client.key,
'trusted': authtoken.client.trusted,
'scope': client_resources,
}
return api_result('ok', **params)


@csrf.exempt
@lastuser_oauth.route('/api/1/resource/sync', methods=['POST'])
@requires_client_login
Expand Down

0 comments on commit 9c049d2

Please sign in to comment.