Skip to content

Commit 32bc165

Browse files
author
Lee Liming
committed
Added token introspection example
1 parent 5adc232 commit 32bc165

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

auth_example.py

100644100755
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,26 @@ def index():
2727
if not session.get('is_authenticated'):
2828
return redirect(url_for('login'))
2929
logout_uri = url_for('logout', _external=True)
30+
31+
# get the stored access token for the Auth API and use it
32+
# to authorize stuff AS THE AUTHENTICATED USER
3033
auth_token = str(session.get('tokens')['auth.globus.org']['access_token'])
3134
ac = globus_sdk.AuthClient(authorizer=globus_sdk.AccessTokenAuthorizer(auth_token))
32-
myoidc = session.get('id_token')
35+
36+
# use Auth API to get more info about the authenticated user
3337
myids = ac.get_identities(ids=str(session.get('username'))).data
38+
39+
# use Auth API to get the standard OIDC userinfo fields (like any OIDC client)
3440
oidcinfo = ac.oauth2_userinfo()
41+
42+
# get the stored OIDC id_token
43+
myoidc = session.get('id_token')
44+
45+
# authenticate to Auth API AS AN APPLICATION and find out still more information
46+
cc = load_app_client()
47+
ir = cc.oauth2_token_introspect(auth_token,include='identities_set').data
48+
49+
# display all this information on the web page
3550
page = '<html><body>\n<p>' + str(session.get('realname')) + ', you are logged in.</p>\n\n'
3651
page = page + '<p>Your local username is: ' + str(session.get('username')) + '</p>\n\n'
3752
page = page + '<p><a href="'+logout_uri+'">Logout now.</a></p>\n\n'
@@ -40,6 +55,7 @@ def index():
4055
page = page + ', and your email is ' + oidcinfo["email"] + '.</p>\n\n'
4156
page = page + '<p>Your OIDC identity is:</p>\n<pre>' + json.dumps(myoidc,indent=3) + '</pre>\n\n'
4257
page = page + '<p>Your Globus Auth identity is:</p>\n<pre>' + json.dumps(myids,indent=3) + '</pre>\n\n'
58+
page = page + '<p>Token introspection tells me:</p>\n<pre>' + json.dumps(ir,indent=3) + '</pre>\n\n'
4359
page = page + '</body></html>'
4460
return(page)
4561

0 commit comments

Comments
 (0)