41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
|
import globus_sdk
|
||
|
|
||
|
|
||
|
CLIENT_ID = '0e37e11f-29e6-404c-86e2-d8d87d0c68ee'
|
||
|
|
||
|
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
|
||
|
client.oauth2_start_flow(refresh_tokens=True)
|
||
|
|
||
|
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)
|
||
|
|
||
|
globus_auth_data = token_response.by_resource_server['auth.globus.org']
|
||
|
|
||
|
# let's get stuff for the Globus Transfer service
|
||
|
globus_transfer_data = token_response.by_resource_server['transfer.api.globus.org']
|
||
|
# the refresh token and access token, often abbr. as RT and AT
|
||
|
transfer_rt = globus_transfer_data['refresh_token']
|
||
|
transfer_at = globus_transfer_data['access_token']
|
||
|
expires_at_s = globus_transfer_data['expires_at_seconds']
|
||
|
|
||
|
# Now we've got the data we need, but what do we do?
|
||
|
# That "GlobusAuthorizer" from before is about to come to the rescue
|
||
|
|
||
|
authorizer = globus_sdk.RefreshTokenAuthorizer(
|
||
|
transfer_rt, client, access_token=transfer_at)
|
||
|
|
||
|
# and try using `tc` to make TransferClient calls. Everything should just
|
||
|
# work -- for days and days, months and months, even years
|
||
|
tc = globus_sdk.TransferClient(authorizer=authorizer)
|
||
|
|
||
|
print("The Transfer Token is:" + transfer_rt)
|
||
|
print("The Access Token: " + transfer_at)
|
||
|
print("Expires At: " + str(expires_at_s))
|