Tm1Login
from skipcheck_tm1_testcontainers import Tm1LoginA 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 property | Whether this is a pass-through login (Tm1Database.pass_through_login). |
authorization property | The Authorization header of a pass-through login, as a client that logs in itself sends it on any request. |
is_oauth2 property | Whether this is a login through OAuth 2.0 (Tm1Database.oauth2_login), rather than through the instance's application. |
password property | The user's password. |
token_url property | Where a token is asked for. |
instance property | The instance this login is for. |
user property | The user this logs in as. |
client_id property | 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 | The application's client secret; empty for an OAuth 2.0 or a pass-through login. |
auth_url property | Where a session or a token is asked for, as seen from the host, ending in /, e.g. |
cookie | The session cookie, TM1SessionId=..., for a Cookie header. |
token | A bearer token for the application, a JWT, from TM1's token endpoint (the OAuth 2.0 client-credentials grant). |
session | Logs the user in with an Authorization header of your own, such as "Bearer " + login.token(), and returns the new session's cookie, TM1SessionId=.... |
authorize | Adds this login's session cookie to a request. |
authorize_with_token | Adds 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) -> Noneis_pass_through
propertyis_pass_through: boolWhether this is a pass-through login (Tm1Database.pass_through_login): one TM1 v12 checks with a TM1 11 server.
authorization
propertyauthorization: strThe 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
propertyis_oauth2: boolWhether this is a login through OAuth 2.0 (Tm1Database.oauth2_login), rather than through the instance's application.
password
propertypassword: strThe 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
propertytoken_url: strWhere 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
propertyinstance: strThe instance this login is for.
user
propertyuser: strThe 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
propertyclient_id: strThe 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
propertyclient_secret: strThe application's client secret; empty for an OAuth 2.0 or a pass-through login.
auth_url
propertyauth_url: strWhere a session or a token is asked for, as seen from the host, ending in /, e.g. http://localhost:54321/tm1/auth/v1/.
cookie
cookie() -> strThe session cookie, TM1SessionId=..., for a Cookie header. Logs in the first time, with the application's credentials as Basic authentication, for an OAuth 2.0 login with a token from the provider, or for a pass-through login with its header, and keeps the session. A RuntimeError if TM1 refuses the login.
token
token() -> strA 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) -> strLogs 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) -> _RequestAdds 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) -> _RequestAdds 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.