skipcheck

TM1 Testcontainers · Docs · More

Tm1Login

from skipcheck_tm1_testcontainers import Tm1Login

A user's login to a TM1 v12 instance, through one of the instance's applications ("service-to-service"): TM1 v12 has no passwords of its own, so the application's client ID and secret vouch for the user's name.

A login belongs to an instance: its session serves every database there. Whether the user may do anything in a database depends on the user existing in it.

Get one from Tm1Database.login or Tm1Database.login, then either let it log in for you (authorize or cookie), or hand client_id, client_secret and user to a client that logs in itself.

Two other kinds log a user in as themselves: an OAuth 2.0 login (Tm1Database.oauth2_login), with a token from the engine's Keycloak, and a pass-through login (Tm1Database.pass_through_login), with the Authorization header a TM1 11 server takes (authorization). authorize and cookie work for all three.

Members

__init__ constructor
is_pass_through propertyWhether this is a pass-through login (Tm1Database.pass_through_login).
authorization propertyThe Authorization header of a pass-through login, as a client that logs in itself sends it on any request.
is_oauth2 propertyWhether this is a login through OAuth 2.0 (Tm1Database.oauth2_login), rather than through the instance's application.
password propertyThe user's password.
token_url propertyWhere a token is asked for.
instance propertyThe instance this login is for.
user propertyThe user this logs in as.
client_id propertyThe application's client ID; the Keycloak client's for an OAuth 2.0 login, and empty for a pass-through login, which goes through no application.
client_secret propertyThe application's client secret; empty for an OAuth 2.0 or a pass-through login.
auth_url propertyWhere a session or a token is asked for, as seen from the host, ending in /, e.g.
cookieThe session cookie, TM1SessionId=..., for a Cookie header.
tokenA bearer token for the application, a JWT, from TM1's token endpoint (the OAuth 2.0 client-credentials grant).
sessionLogs the user in with an Authorization header of your own, such as "Bearer " + login.token(), and returns the new session's cookie, TM1SessionId=....
authorizeAdds this login's session cookie to a request.
authorize_with_tokenAdds this login's token to a request as Authorization.

__init__

constructor
__init__(auth_url: str, instance: str, client_id: str, client_secret: str, user: str) -> None

is_pass_through

property
is_pass_through: bool

Whether this is a pass-through login (Tm1Database.pass_through_login): one TM1 v12 checks with a TM1 11 server.

authorization

property
authorization: str

The Authorization header of a pass-through login, as a client that logs in itself sends it on any request: Basic with the user's name and password on the TM1 11 server, or CAMNamespace when that server is in Cognos (CAM) security. A RuntimeError for a login that isn't pass-through.

is_oauth2

property
is_oauth2: bool

Whether this is a login through OAuth 2.0 (Tm1Database.oauth2_login), rather than through the instance's application.

password

property
password: str

The user's password: at the identity provider for an OAuth 2.0 login, and on the TM1 11 server (or in Cognos) for a pass-through login. Empty otherwise, as TM1 v12 keeps none, and for a pass-through login made from a header alone.

token_url

property
token_url: str

Where a token is asked for: the identity provider's token endpoint for an OAuth 2.0 login, as seen from the host, and TM1's own otherwise.

instance

property
instance: str

The instance this login is for.

user

property
user: str

The user this logs in as. For a pass-through login it's the name on the TM1 11 server, or in Cognos: with a server in CAM security the user's name in TM1 v12 is its CAMID. Empty for a pass-through login made from a header alone.

client_id

property
client_id: str

The application's client ID; the Keycloak client's for an OAuth 2.0 login, and empty for a pass-through login, which goes through no application.

client_secret

property
client_secret: str

The application's client secret; empty for an OAuth 2.0 or a pass-through login.

auth_url

property
auth_url: str

Where a session or a token is asked for, as seen from the host, ending in /, e.g. http://localhost:54321/tm1/auth/v1/.

token

token() -> str

A bearer token for the application, a JWT, from TM1's token endpoint (the OAuth 2.0 client-credentials grant). It names no user: send it as Authorization: Bearer with the user's name to get a session, as session does. A RuntimeError if TM1 refuses the application's credentials.

For an OAuth 2.0 login, an access token for the user from the provider, by the password grant: a new one each time. A RuntimeError for a pass-through login, which has no token.

session

session(authorization: str) -> str

Logs the user in with an Authorization header of your own, such as "Bearer " + login.token(), and returns the new session's cookie, TM1SessionId=.... Each call makes a session; cookie keeps one. A RuntimeError if TM1 refuses the login, or for an OAuth 2.0 or a pass-through login, which has no session endpoint to ask.

authorize

authorize(request: _Request) -> _Request

Adds this login's session cookie to a request: its headers, as a dict (httpx2.get(url, headers=login.authorize({}))), or an httpx2.Request. Returns what it was given.

authorize_with_token

authorize_with_token(request: _Request) -> _Request

Adds this login's token to a request as Authorization: Bearer, as a program with a token of its own would send it: to its headers, as a dict, or to an httpx2.Request. For an OAuth 2.0 login, a new token from the provider each time; TM1 answers with a session cookie. A RuntimeError for a login through the application, whose token TM1 takes only at its session endpoint (session), and for a pass-through login, which has none.