skipcheck

TM1 Testcontainers · Docs · More

Tm1Login

using 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 (AuthorizeAsync or CookieAsync), or hand ClientId, ClientSecret and User 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 (Authorization). AuthorizeAsync and CookieAsync work for all three.

Members

IsPassThrough propertyWhether this is a pass-through login (Tm1Database.PassThroughLogin).
Authorization propertyThe Authorization header of a pass-through login, as a client that logs in itself sends it on any request.
IsOAuth2 propertyWhether this is a login through OAuth 2.0 (Tm1Database.OAuth2Login), rather than through the instance's application.
Password propertyThe user's password.
TokenUrl propertyWhere a token is asked for.
Instance propertyThe instance this login is for.
User propertyThe user this logs in as.
ClientId propertyThe application's client ID; for an OAuth 2.0 login, the client its tokens are asked for as, and empty for a pass-through login, which goes through no application.
ClientSecret propertyThe application's client secret; empty for an OAuth 2.0 login, whose client is a public one, and for a pass-through login.
AuthUrl propertyWhere a session or a token is asked for, as seen from the host, ending in /, e.g.
CookieAsyncThe session cookie, TM1SessionId=..., for a Cookie header.
TokenAsyncA bearer token for the application, from TM1's token endpoint (the OAuth 2.0 client-credentials grant).
SessionAsyncLogs the user in with an Authorization header of your own, such as "Bearer " + await TokenAsync(), and returns the new session's cookie.
AuthorizeAsyncAdds this login's session cookie to request, logging in first if it hasn't.
AuthorizeWithTokenAsyncAdds this login's token to request as Authorization.
ToString

IsPassThrough

property
bool IsPassThrough

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

Authorization

property
string Authorization

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.

Throws

InvalidOperationException
A login that isn't pass-through.

IsOAuth2

property
bool IsOAuth2

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

Password

property
string Password

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.

TokenUrl

property
string TokenUrl

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.

Throws

InvalidOperationException
An OAuth 2.0 login's Keycloak isn't started.

Instance

property
string Instance

The instance this login is for.

User

property
string User

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.

ClientId

property
string ClientId

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

ClientSecret

property
string ClientSecret

The application's client secret; empty for an OAuth 2.0 login, whose client is a public one, and for a pass-through login.

AuthUrl

property
string AuthUrl

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

CookieAsync

Task<string> CookieAsync(CancellationToken cancellationToken = default)

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 TM1 a token from the provider, and a pass-through login its header; each keeps the session TM1 answers with.

Throws

InvalidOperationException
TM1 refuses the login.

TokenAsync

Task<string> TokenAsync(CancellationToken cancellationToken = default)

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 SessionAsync does. For an OAuth 2.0 login, a new access token for the user from the identity provider, with the user's password: one TM1 takes as Authorization: Bearer on any request.

Returns

The access token, a JWT.

Throws

InvalidOperationException
TM1 refuses the application's credentials, or the provider the user's; or this is a pass-through login, which has no token.

SessionAsync

Task<string> SessionAsync(string authorization, CancellationToken cancellationToken = default)

Logs the user in with an Authorization header of your own, such as "Bearer " + await TokenAsync(), and returns the new session's cookie. Each call makes a session; CookieAsync keeps one.

Returns

The session cookie, TM1SessionId=....

Throws

InvalidOperationException
TM1 refuses the login; or this is an OAuth 2.0 login, whose token TM1 takes on any request and not here; or a pass-through login, whose header TM1 takes the same way.

AuthorizeAsync

Task<HttpRequestMessage> AuthorizeAsync(HttpRequestMessage request, CancellationToken cancellationToken = default)

Adds this login's session cookie to request, logging in first if it hasn't. Send it with a client that keeps no cookies of its own (UseCookies = false), or the header is replaced.

Returns

The same request.

AuthorizeWithTokenAsync

Task<HttpRequestMessage> AuthorizeWithTokenAsync(HttpRequestMessage request, CancellationToken cancellationToken = default)

Adds this login's token to request as Authorization: Bearer, as a program with a token of its own would send it. For an OAuth 2.0 login, a new token from the provider each time; TM1 answers with a session cookie.

Returns

The same request.

Throws

InvalidOperationException
A login through the application, whose token TM1 takes only at its session endpoint (SessionAsync); or a pass-through login, which has no token.

ToString

string ToString()