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 property | Whether this is a pass-through login (Tm1Database.PassThroughLogin). |
Authorization property | The Authorization header of a pass-through login, as a client that logs in itself sends it on any request. |
IsOAuth2 property | Whether this is a login through OAuth 2.0 (Tm1Database.OAuth2Login), rather than through the instance's application. |
Password property | The user's password. |
TokenUrl property | Where a token is asked for. |
Instance property | The instance this login is for. |
User property | The user this logs in as. |
ClientId property | 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 | 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 | Where a session or a token is asked for, as seen from the host, ending in /, e.g. |
CookieAsync | The session cookie, TM1SessionId=..., for a Cookie header. |
TokenAsync | A bearer token for the application, from TM1's token endpoint (the OAuth 2.0 client-credentials grant). |
SessionAsync | Logs the user in with an Authorization header of your own, such as "Bearer " + await TokenAsync(), and returns the new session's cookie. |
AuthorizeAsync | Adds this login's session cookie to request, logging in first if it hasn't. |
AuthorizeWithTokenAsync | Adds this login's token to request as Authorization. |
ToString |
IsPassThrough
propertybool IsPassThroughWhether this is a pass-through login (Tm1Database.PassThroughLogin): one TM1 v12 checks
with a TM1 11 server.
Authorization
propertystring AuthorizationThe 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
propertybool IsOAuth2Whether this is a login through OAuth 2.0 (Tm1Database.OAuth2Login), rather than through
the instance's application.
Password
propertystring PasswordThe 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
propertystring TokenUrlWhere 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
propertystring InstanceThe instance this login is for.
User
propertystring UserThe 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
propertystring ClientIdThe 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
propertystring ClientSecretThe application's client secret; empty for an OAuth 2.0 login, whose client is a public one, and for a pass-through login.
AuthUrl
propertystring AuthUrlWhere 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()