Tm1Login
import { Tm1Login } from "@skipcheck/tm1-testcontainers";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
getClientId, getClientSecret and getUser to a client
that logs in itself.
Two other kinds log a user in as themselves: an OAuth 2.0 login
(Tm1Database.oauth2Login), with a token from the engine's Keycloak, and a
pass-through login (Tm1Database.passThroughLogin), with the
Authorization header a TM1 11 server takes (getAuthorization).
authorize and cookie work for all three.
Members
Tm1Login constructor | A login of user through the application whose credentials these are; or, with oauth2, through OAuth 2.0, with tokens from the engine's Keycloak; or, with passThrough, with the header a TM1 server behind the engine takes. |
oauth2 static | A login through OAuth 2.0. |
passThrough static | A pass-through login, with the header a TM1 server behind the engine takes. |
isOAuth2 | Whether this is a login through OAuth 2.0 (Tm1Database.oauth2Login), rather than through the instance's application. |
isPassThrough | Whether this is a pass-through login (Tm1Database.passThroughLogin). |
getAuthorization | The Authorization header of a pass-through login, as a client that logs in itself sends it on any request. |
getPassword | The user's password. |
getTokenUrl | Where a token is asked for. |
getInstance | The instance this login is for. |
getUser | The user this logs in as. |
getClientId | The application's client ID; for an OAuth 2.0 login, the provider's client a token is asked for as, and empty for a pass-through login, which goes through no application. |
getClientSecret | The application's client secret; empty for an OAuth 2.0 login, whose client has none, and for a pass-through login. |
getAuthUrl | Where a session or a token is asked for, as seen from the host, e.g. |
cookie | The session cookie, TM1SessionId=..., for a Cookie header. |
token | A bearer token for the application, 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 " + (await login.token()), and returns the new session's cookie. |
authorize | Adds this login's session cookie to a request. |
authorizeWithToken | Adds this login's token to a request as Authorization. |
toString | The user and the instance, never the secret. |
Tm1Login
constructorconstructor(authUrl: string, instance: string, clientId: string, clientSecret: string, user: string, oauth2?: OAuth2, passThrough?: PassThrough)A login of user through the application whose credentials these are; or, with oauth2, through OAuth 2.0, with tokens from the engine's Keycloak; or, with passThrough, with the header a TM1 server behind the engine takes.
oauth2
staticstatic oauth2(user: string, oauth2: OAuth2): Tm1LoginA login through OAuth 2.0. Addresses are asked of the database when they're needed: a login can be made before the engine has started.
passThrough
staticstatic passThrough(user: string, passThrough: PassThrough): Tm1LoginA pass-through login, with the header a TM1 server behind the engine takes.
isOAuth2
isOAuth2(): booleanWhether this is a login through OAuth 2.0 (Tm1Database.oauth2Login), rather than through the instance's application.
isPassThrough
isPassThrough(): booleanWhether this is a pass-through login (Tm1Database.passThroughLogin): one TM1 v12 checks with a TM1 11 server.
getAuthorization
getAuthorization(): stringThe 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.
Returns
- the header's value
Throws
- IllegalStateException for a login that isn't pass-through
getPassword
getPassword(): stringThe 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.
getTokenUrl
getTokenUrl(): stringWhere 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.
getInstance
getInstance(): stringThe instance this login is for.
getUser
getUser(): stringThe 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.
getClientId
getClientId(): stringThe application's client ID; for an OAuth 2.0 login, the provider's client a token is asked for as, and empty for a pass-through login, which goes through no application.
getClientSecret
getClientSecret(): stringThe application's client secret; empty for an OAuth 2.0 login, whose client has none, and for a pass-through login.
getAuthUrl
getAuthUrl(): stringWhere a session or a token is asked for, as seen from the host, e.g. http://localhost:54321/tm1/auth/v1/: the instance's authentication root, ending in /.
cookie
cookie(): Promise<string>The session cookie, TM1SessionId=..., for a Cookie header. Logs in the first time, with the application's credentials as Basic authentication, and keeps the session. An OAuth 2.0 login sends the provider's token on a request instead, and a pass-through login its header: each keeps the session TM1 gives it.
Throws
- IllegalStateException if TM1 refuses the login
token
token(): Promise<string>A bearer token for the application, 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.
For an OAuth 2.0 login it's the user's own token, from the identity provider, by the password grant: TM1 takes it on any request (authorizeWithToken).
Returns
- the access token, a JWT
Throws
- IllegalStateException if TM1 refuses the application's credentials, or the provider the user's, or for a pass-through login, which has no token
session
session(authorization: string): Promise<string>Logs the user in with an Authorization header of your own, such as "Bearer " + (await login.token()), and returns the new session's cookie. Each call makes a session; cookie keeps one.
Parameters
authorization- the
Authorizationheader's value
Returns
- the session cookie,
TM1SessionId=...
Throws
- IllegalStateException if TM1 refuses the login, or for an OAuth 2.0 or a pass-through login, which has no session to ask for
authorize
authorize(request: RequestInit = {}): Promise<RequestInit>Adds this login's session cookie to a request: what fetch takes as its second argument, as in fetch(url, await db.login().authorize()).
Parameters
request- the request being built; none for a plain GET
Returns
requestwith theCookieheader, as a new object
authorizeWithToken
authorizeWithToken(request: RequestInit = {}): Promise<RequestInit>Adds this login's token to a request as Authorization: Bearer, as a program with a token of its own would send it: what fetch takes as its second argument. For an OAuth 2.0 login, a new token from the provider each time; TM1 answers with a session cookie.
Parameters
request- the request being built; none for a plain GET
Returns
requestwith theAuthorizationheader, as a new object
Throws
- IllegalStateException 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
toString
toString(): stringThe user and the instance, never the secret.