Created
April 15, 2022 19:37
-
-
Save marcelkore/06d5c58d65d7ceb0833dc37f951e549f to your computer and use it in GitHub Desktop.
function that returns an authenticated box client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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