Skip to content

Instantly share code, notes, and snippets.

@marcelkore
Created April 15, 2022 19:37
Show Gist options
  • Save marcelkore/06d5c58d65d7ceb0833dc37f951e549f to your computer and use it in GitHub Desktop.
Save marcelkore/06d5c58d65d7ceb0833dc37f951e549f to your computer and use it in GitHub Desktop.
function that returns an authenticated box client
def get_authenticated_client(configPath):
"""Get an authenticated Box client for a JWT service account
Arguments:
configPath {str} -- Path to the JSON config file for your Box JWT app
Returns:
Client -- A Box client for the JWT service account
Raises:
ValueError -- if the configPath is empty or cannot be found.
"""
if os.path.isfile(configPath) == False:
raise ValueError(
f"configPath must be a path to the JSON config file for your Box JWT app"
)
auth = JWTAuth.from_settings_file(configPath)
print("Authenticating...")
auth.authenticate_instance()
return Client(auth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment