Skip to content

Globus User Credential Lookup Sample Code

Steven Lee edited this page Aug 7, 2018 · 1 revision


  1. Install Globus SDK by running pip install globus-sdk as root.
  2. Obtain access and refresh tokens if you don't have them:
    1. Define CLIENT_ID environment variable with your app's client ID.
    2. Run the code below.
  3. Update the following environment variables with the information obtained from the previous step:
  4. Run the like this: -s <globus sub>


import os
import globus_sdk
from globus_sdk import AuthClient,AccessTokenAuthorizer

CLIENT_ID = os.environ['CLIENT_ID']

client = globus_sdk.NativeAppAuthClient(CLIENT_ID)

authorize_url = client.oauth2_get_authorize_url()
print('Please go to this URL and login: {0}'.format(authorize_url))

# this is to work on Python2 and Python3 -- you can just use raw_input() or
# input() for your specific version
get_input = getattr(__builtins__, 'raw_input', input)
auth_code = get_input(
    'Please enter the code you get after login here: ').strip()
token_response = client.oauth2_exchange_code_for_tokens(auth_code)

print token_response.by_resource_server['']

import os
import argparse
import globus_sdk
from globus_sdk import AuthClient,AccessTokenAuthorizer

parser = argparse.ArgumentParser(description='Returns Globus user identity fields')
parser.add_argument('-s', dest='globus_sub', required=True,
                   help='Globus sub to look up')
args = parser.parse_args()

CLIENT_ID = os.environ['CLIENT_ID']
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)

my_authorizer = globus_sdk.RefreshTokenAuthorizer(
	os.environ['REFRESH_TOKEN'], client, 

ac = AuthClient(authorizer=my_authorizer)
r = ac.get_identities(ids=args.globus_sub)