({ appConfig }: { appConfig: Readonly<SelfManagedAppConfig> })
| 217 | }; |
| 218 | |
| 219 | constructor({ appConfig }: { appConfig: Readonly<SelfManagedAppConfig> }) { |
| 220 | this.#appConfig = appConfig; |
| 221 | this.mzHttpUrlScheme = this.#appConfig.environmentdScheme; |
| 222 | this.mzWebsocketUrlScheme = this.#appConfig.environmentdWebsocketScheme; |
| 223 | this.authApiBasePath = `${this.#appConfig.environmentdScheme}://${this.#appConfig.environmentdConfig.environmentdHttpAddress}`; |
| 224 | this.authMode = this.#appConfig.authMode; |
| 225 | |
| 226 | if (this.authMode === "Oidc") { |
| 227 | this.oidcManagerInitializationPromise = MzOidcUserManager.create().then( |
| 228 | (manager) => { |
| 229 | this.oidcManager = manager; |
| 230 | return manager; |
| 231 | }, |
| 232 | ); |
| 233 | // When OIDC is configured, users can authenticate via either OIDC or |
| 234 | // password. The OIDC middleware adds a Bearer token if one exists; |
| 235 | // otherwise no auth header is sent and the session cookie is used |
| 236 | // implicitly. The 401 redirect handles expired/missing sessions. |
| 237 | this.mzApiFetch = withMiddleware( |
| 238 | this.#mzApiWithAuthRedirect, |
| 239 | this.#oidcAuthMiddleware, |
| 240 | ); |
| 241 | } else if (this.authMode === "None") { |
| 242 | this.mzApiFetch = withMiddleware( |
| 243 | globalFetch, |
| 244 | this.#flexibleDeploymentAuthMiddleware, |
| 245 | ); |
| 246 | } else { |
| 247 | this.mzApiFetch = this.#mzApiWithAuthRedirect; |
| 248 | } |
| 249 | |
| 250 | this.getWsAuthConfig = () => { |
| 251 | if (this.authMode === "Oidc") { |
| 252 | const idToken = this.oidcManager?.getIdToken(); |
| 253 | if (idToken) { |
| 254 | return buildTokenAuthConfig(idToken); |
| 255 | } |
| 256 | // No OIDC token — user authenticated via password, session cookie |
| 257 | // is sent implicitly so no explicit auth config is needed. |
| 258 | return null; |
| 259 | } |
| 260 | // Unintuitively, we return an auth config when authMode is "None". This is because |
| 261 | // the authenticated websocket API gets the necessary information via the http-only cookie |
| 262 | // and errors if you try to send a websocket message with the auth config. |
| 263 | if (this.authMode === "None") { |
| 264 | return buildPasswordAuthConfig(FLEXIBLE_DEPLOYMENT_USER); |
| 265 | } |
| 266 | return null; |
| 267 | }; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | export class ImpersonationApiClient |
nothing calls this directly
no test coverage detected