Globus SDK TokenStorage

A Globus SDK contrib module providing simple token storage.

Basic Usage

Install with pip install globus-sdk-tokenstorage

You can then import helpers from globus_sdk_tokenstorage. For example:

import os
import globus_sdk
from globus_sdk_tokenstorage import SimpleJSONFileAdapter

my_file_adapter = SimpleJSONFileAdapter(

if not my_file_adapter.file_exists():
    # ... do a login low, getting back initial tokens
    # elided for simplicity here
    token_response = ...
    # now store the tokens, and pull out the tokens for the
    # resource server we want
    by_rs = token_response.by_resource_server
    tokens = by_rs['']
    # otherwise, we already did this whole song-and-dance, so just
    # load the tokens from that file
    tokens = my_file_adapter.read_as_dict()

# RereshTokenAuthorizer and ClientCredentialsAuthorizer both use
# `on_refresh` callbacks
# this feature is therefore only relevant for those auth types
# auth_client is the internal auth client used for refreshes,
# and which was used in the login flow
# note that this is all normal SDK usage wherein my_file_adapter
# is providing the on_refresh callback
auth_client = ...
authorizer = globus_sdk.RefreshTokenAuthorizer(
    tokens['refresh_token'], auth_client,
    tokens['access_token'], tokens['access_token_expires'],

# or, for client credentials
authorizer = globus_sdk.ClientCredentialsAuthorizer(
    auth_client, [''],

# and then use as normal, tada!
tc = globus_sdk.TransferClient(authorizer=authorizer)

Full Library Contents

class globus_sdk_tokenstorage.abstract_base.AbstractStorageAdapter

Bases: object


By default, the on_refresh handler for a token storage adapter simply stores the token response.

class globus_sdk_tokenstorage.file_adapters.AbstractFileAdapter

Bases: globus_sdk_tokenstorage.abstract_base.AbstractStorageAdapter

File adapters are for single-user cases, where we can assume that there’s a simple file-per-user and users are only ever attempting to read their own files.


Check if the file used by this file storage adapter exists.

class globus_sdk_tokenstorage.SimpleJSONFileAdapter(filename, resource_server=None, scopes=None)

Bases: globus_sdk_tokenstorage.file_adapters.AbstractFileAdapter

  • filename – the name of the file to write to and read from
  • resource_server – the resource server name for tokens to look up in a token response object
  • scopes – a list of scope names for tokens to look up in a token response object

A storage adapter for storing tokens in JSON files. Callers must provide exactly one of resource_server and scopes


By default, self.on_refresh is just an alias for this function.

Given a token response, extract the token data for the configured scopes or resource servers of this file adapter and write it to self.filename as JSON data. Additionally will write the version of globus_sdk_tokenstorage which was in use.

Under the assumption that this may be running on a system with multiple local users, this sets the umask such that only the owner of the resulting file can read or write it.


Load the config file contents as JSON and return the resulting dict object.

Although the whole token response is passed in for, this will only return the token data for the particular scopes or resource server for which this File Adapter is configured.