set_auth_token | Set Authentication Token | Open Analytics Framework - set_auth_token - Teradata VantageCloud Lake

Lake - Analyze Your Data with ClearScape Analytics™

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2026-02-20
dita:mapPath
tcl1683670667798.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
tcl1683670667798

Use set_auth_token() to generate and set the authentication token required to access services running on VantageCloud Lake.

  • You must have a privilege to login with a NULL password to use set_auth_token(). Refer to GRANT LOGON for more details.
  • When "auth_mech" is not specified, use the following combination of arguments to derive authentication mechanism.
    • If "base_url" and "client_id" are specified, then token generation is done through OAuth.
    • If "base_url", "pat_token", "pem_file" are specified, then token generation is done using PAT.
    • If "base_url", "username" and "password" are specified, then authentication is done via Basic authentication mechanism using user credentials.
    • If "base_url" and "auth_token" are specified, then the readily available token is used.
    • If only "base_url" is specified, then token generation is done through OAuth.
  • Refresh token works only for OAuth authentication.
  • Use the argument "kid" only when key used during the pem file generation is different from pem file name. For example, if you use the key as 'key1' while generating pem file and the name of the pem file is 'key1(1).pem', then pass value 'key1' to the argument "kid".
  • Instances of this class can be passed in to the Enterprise Vector Store APIs to use a specific token instead of the globally configured token.
  • Each new instance creation overwrites the existing authentication token available globally but will not invalidate the existing token.

Required Parameters

base_url
Specifies the endpoint URL for a given environment in VantageCloud Lake.
pem_file
Required, if PAT authentication is to be used, optional otherwise.

Specifies the path to Private Key file which is generated from VantageCloud Lake Console.

Teradata recommends not to change the name of the file generated from VantageCloud Lake Console. If the name of the file is changed, then authentication token generated from this class will not work.
pat_token
Required, if PAT authentication is to be used, optional otherwise.

Specifies the PAT token generated from VantageCloud Lake Console.

Optional Parameters

client_id
Specifies the id of the application that requests the access token from VantageCloud Lake.
Typically, it has the format client_id = <org_name>-oaf-device. You can get the organization name from the URL used to access the VantageCloud Lake Console. For example, https://organization_name.innovationlabs.teradata.com.
**kwargs
username
Required if create_context() is not called before set_auth_token().

Specifies the user for which authentication is to be requested.

If not specified, then user associated with current connection is used.

Use this option only if name of the database username has lower case letters.
expiration_time
Specifies the expiration time of the token in seconds. After expiry time JWT token expires and UserEnv methods do not work, user should regenerate the token.
This option is used only for PAT and not for OAuth.

Default value: 31536000

auth_token
Specifies the authentication token required to access services running on VantageCloud Lake.
  • If "auth_token" is set through this class, then this class should always be used only after create_context().
  • Use this option only if user has got JWT token and wants to set the same instead of generating it again from this class.
kid
Specifies the name of the key which is used while generating 'pem_file'.
auth_url
Specifies the endpoint URL for a keycloak server.
rest_client
Specifies the service for which keycloak token is to be generated.

Permitted values: "VECTORSTORE"

Default value: "VECTORSTORE"

auth_mech
Specifies the mechanism to be used for generating authentication token.
When "auth_mech" is provided, other arguments are used in the following combination as per value of "auth_mech":
  • OAuth: Token generation is done through OAuth by using client id which can be specified by user in "client_id" argument or can be derived internally from "base_url".
  • PAT : Token generation is done using "pat_token" and "pem_file".
  • BASIC: Authentication is done via Basic authentication mechanism using user credentials passed in "username" and "password" arguments.
  • JWT : Readily available token in "auth_token" argument is used.
  • KEYCLOAK: Token generation is done using keycloak.

Permitted values: "OAuth", "PAT", "BASIC", "JWT", "KEYCLOAK".

validate_jwt
Specifies whether to validate generated JWT token or not.
Applicable only when "auth_mech" is "PAT".

Default value: True

valid_from
Specifies epoch seconds representing time from which JWT token will be valid.
Applicable only when "auth_mech" is "PAT".

Default value: 0

This class returns True if the operation is successful.

Example 1: Set the authentication token using default client_id

>>> import getpass
>>> set_auth_token(ues_url=getpass.getpass("ues_url : "))

Example 2: Set the authentication token by specifying the client_id

>>> import getpass
>>> set_auth_token(ues_url=getpass.getpass("ues_url : "),
...                   client_id=getpass.getpass("client_id : "))

Example 3: Set the authentication token by specifying the pem_file and pat_token

>>> import getpass
>>> set_auth_token(ues_url=getpass.getpass("ues_url : "),
...                pat_token=getpass.getpass("pat_token : "),
...                pem_file=getpass.getpass("pem_file : "))
True

Example 4: Set the authentication token by specifying the pem_file and pat_token and username

>>> import getpass
>>> set_auth_token(ues_url=getpass.getpass("ues_url : "),
...                pat_token=getpass.getpass("pat_token : "),
...                pem_file=getpass.getpass("pem_file : "))
...                username = "alice")
True

Example 5: Set the authentication token by specifying the pem_file and pat_token and username and kid

>>> import getpass
>>> set_auth_token(base_url=getpass.getpass("base_url : "),
...                pat_token=getpass.getpass("pat_token : "),
...                pem_file=getpass.getpass("pem_file : ")
...                kid="key1")
Authentication token is generated, authenticated and set for the session.
True

Example 6: Set the authentication token via Basic Authentication mechanism by specifying the base_url, username, and password

>>> import getpass
>>> set_auth_token(base_url=getpass.getpass("base_url : "),
...                username=getpass.getpass("username : "),
...                password=getpass.getpass("password : "))
Authentication token is generated and set for the session.
True

Example 7: Set the authentication token by specifying base_url and auth_mech as "OAuth"

>>> import getpass
>>> set_auth_token(base_url=getpass.getpass("base_url : "),
...                auth_mech="OAuth")
Authentication token is generated and set for the session.
True

Example 8: Set the authentication token by specifying "base_url", "auth_url", "password" and "rest_client" and generating keycloak token internally

>>> import getpass
>>> set_auth_token(base_url=getpass.getpass("base_url : "),
...       auth_url=getpass.getpass("auth_url : "),
...       password=getpass.getpass("password : "),
...       rest_client=getpass.getpass("rest_client : "))
Authentication token is generated and set for the session.
True