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 dotenv import load_dotenv

from archivist.archivist import Archivist
[2]:
%reload_ext dotenv
%dotenv -o notebooks.env
[3]:
# Retrieve the URL

RKVST_URL = getenv("RKVST_URL")
print("RKVST_URL", RKVST_URL)
RKVST_URL https://app.rkvst.io
[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("RKVST_AUTHTOKEN")
print("auth_token", auth_token)
auth_token None
[6]:
# Using the JWT to create an Archivist instance

with Archivist(RKVST_URL, auth_token) as arch:
    print(arch)
Archivist(https://app.rkvst.io)
[7]:
# Part 2 Usng an application client id and secret
#
# To create a new application refer to https://app.rkvst.io/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.

RKVST_APPREG_CLIENT = getenv("RKVST_APPREG_CLIENT")
print("RKVST_APPREG_CLIENT", RKVST_APPREG_CLIENT)

RKVST_APPREG_SECRET = getenv("RKVST_APPREG_SECRET")
print("RKVST_APPREG_SECRET", RKVST_APPREG_SECRET)
RKVST_APPREG_CLIENT cccccccccccccccccccccccccccccccccccc
RKVST_APPREG_SECRET ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
[8]:
# Using the application id and secret to create an Archivist instance

with Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET)) as arch:
    print(arch)
Archivist(https://app.rkvst.io)
[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("RKVST_AUTHTOKEN"),
    client_id=getenv("RKVST_APPREG_CLIENT"),
    client_secret=getenv("RKVST_APPREG_SECRET"),
)
with Archivist(RKVST_URL, auth) as arch:
    print(arch)
Archivist(https://app.rkvst.io)
[ ]: