Skip to content

Instantly share code, notes, and snippets.

@jaswilli
Created August 10, 2017 14:28
Show Gist options
  • Save jaswilli/8eab014af95be19c99ac1326f0142a4c to your computer and use it in GitHub Desktop.
Save jaswilli/8eab014af95be19c99ac1326f0142a4c to your computer and use it in GitHub Desktop.
An example of using the Globus Python SDK and the client credentials grant
import globus_sdk
# Client ID and secret created at https://developers.globus.org
CLIENT_ID = '25b98327-738c-41f8-b1dd-62490e97d9a3'
CLIENT_SECRET = '<secret>'
# The scopes for the resources that will be accessed by this script
SCOPE = 'urn:globus:auth:scope:transfer.api.globus.org:all'
TUTORIAL_ENDPOINT_ID = 'ddb59aef-6d04-11e5-ba46-22000b92c6ec'
# Use the SDK to talk to Globus Auth
auth_client = globus_sdk.ConfidentialAppAuthClient(CLIENT_ID, CLIENT_SECRET)
# Use the "client credentials" grant to get an access token for the identity
# 25b98327-738c-41f8-b1dd-62490e97d9a3@clients.auth.globus.org
token_response = auth_client.oauth2_client_credentials_tokens(
requested_scopes=SCOPE).by_resource_server
transfer_token = token_response['transfer.api.globus.org']['access_token']
# Use the SDK to talk to the Transfer API
# the "authorizer" manages the state of tokens for you
transfer_client = globus_sdk.TransferClient(
authorizer=globus_sdk.AccessTokenAuthorizer(transfer_token))
# Use the access token to do an "ls" against an endpoint
try:
transfer_client.endpoint_autoactivate(TUTORIAL_ENDPOINT_ID)
listing = transfer_client.operation_ls(
TUTORIAL_ENDPOINT_ID, path='/~/')
for entry in listing:
print(entry)
except globus_sdk.exc.TransferAPIError as exc:
print(exc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment