Manage Credentials
[1]:
# Management of authorization credentials
#
# Demonstrating the use of the JWT or application credentials.
# All variables are retrieved from the environment for demonstration purposes.
#
# Part 1 - creating an Archivist Instance using a JWT
# Part 2 - creating an Archivist Instance using an application id and secret
from os import getenv
from archivist.archivist import Archivist
[2]:
%reload_ext dotenv
%dotenv -o notebooks.env
[3]:
# Retrieve the URL
DATATRAILS_URL = getenv("DATATRAILS_URL")
print("DATATRAILS_URL", DATATRAILS_URL)
DATATRAILS_URL https://app.datatrails.ai
[4]:
# Part 1. Using a JWT token
#
# The following steps detail how to use a full JWT bearer token.
[5]:
# extract JWT from environment
auth_token = getenv("DATATRAILS_AUTHTOKEN")
print("auth_token", auth_token)
auth_token None
[6]:
# Using the JWT to create an Archivist instance
with Archivist(DATATRAILS_URL, auth_token) as arch:
print(arch)
Archivist(https://app.datatrails.ai)
[7]:
# Part 2 Usng an application client id and secret
#
# To create a new application refer to https://app.datatrails.ai/developers and scroll down to the
# AppRegistrations POST /archivist/iam/v1/application. Click on 'Try It Out', fill in the request body with a
# required display name. Custom claims can be deleted from the example in most cases.
DATATRAILS_APPREG_CLIENT = getenv("DATATRAILS_APPREG_CLIENT")
print("DATATRAILS_APPREG_CLIENT", DATATRAILS_APPREG_CLIENT)
DATATRAILS_APPREG_SECRET = getenv("DATATRAILS_APPREG_SECRET")
print("DATATRAILS_APPREG_SECRET", DATATRAILS_APPREG_SECRET)
DATATRAILS_APPREG_CLIENT cccccccccccccccccccccccccccccccccccc
DATATRAILS_APPREG_SECRET ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
[8]:
# Using the application id and secret to create an Archivist instance
with Archivist(
DATATRAILS_URL, (DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET)
) as arch:
print(arch)
Archivist(https://app.datatrails.ai)
[9]:
# For convenience all this functionality has been emcapsulated in a convenience function
from archivist.utils import get_auth
auth = get_auth(
auth_token=getenv("DATATRAILS_AUTHTOKEN"),
client_id=getenv("DATATRAILS_APPREG_CLIENT"),
client_secret=getenv("DATATRAILS_APPREG_SECRET"),
)
with Archivist(DATATRAILS_URL, auth) as arch:
print(arch)
Archivist(https://app.datatrails.ai)
[ ]: