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,CAAO,IAAK,CAAA,qCAAA,EAAuC,MAAM,CAAA;AAAA;AAExE","file":"authentication.mjs","sourcesContent":["import { ClientError } from '../client-error';\nimport { UserProfile } from '../types';\nimport { WindowClient } from '../window-client';\n\n/**\n * Describes the authentication pop-up parameters\n */\nexport interface AuthPopUpParams {\n  /**\n   * The URL for the authentication pop-up.\n   */\n  url: string;\n\n  /**\n   * The preferred width for the pop-up. This value can be ignored if outside the acceptable bounds.\n   */\n  width?: number;\n\n  /**\n   * The preferred height for the pop-up. This value can be ignored if outside the acceptable bounds.\n   */\n  height?: number;\n\n  /**\n   * Some identity providers restrict their authentication pages from being displayed in embedded browsers (e.g., a web view inside of a native application)\n   * If the identity provider you are using prevents embedded browser usage, this flag should be set to `true` to enable the authentication page specified in\n   * the {@link url} property to be opened in an external browser.\n   * If this flag is `false`, the page will be opened directly within the current hosting application.\n   *\n   * This flag is ignored when the host for the application is a web app (as opposed to a native application) as the behavior is unnecessary in a web-only\n   * environment without an embedded browser.\n   */\n  isExternal?: boolean;\n}\n\n/**\n * Describes authentication token request parameters\n */\nexport interface AuthTokenRequestParams {\n  /**\n   * An list of resources for which to acquire the access token; only for internal Microsoft usage\n   */\n  resources?: string[];\n\n  /**\n   * An optional list of claims which to pass to Microsoft Entra when requesting the access token.\n   */\n  claims?: string[];\n\n  /**\n   * An optional flag indicating whether to attempt the token acquisition silently or allow a prompt to be shown.\n   */\n  silent?: boolean;\n\n  /**\n   * An optional identifier of the home tenant for which to acquire the access token for (used in cross-tenant shared channels).\n   */\n  tenantId?: string;\n}\n\nexport class AuthenticationClient {\n  readonly window: WindowClient;\n\n  constructor(client: WindowClient) {\n    this.window = client;\n  }\n\n  async getToken(params?: AuthTokenRequestParams) {\n    const [ok, res] = await this.window.send<[boolean, string]>(\n      'authentication.getAuthToken',\n      params?.resources,\n      params?.claims,\n      params?.silent,\n      params?.tenantId\n    );\n\n    if (!ok) {\n      throw { errorCode: 500, message: res };\n    }\n\n    return res;\n  }\n\n  async getUser() {\n    const [ok, res] =\n      await this.window.send<[boolean, UserProfile | ClientError]>('authentication.getUser');\n\n    if (!ok) {\n      throw res;\n    }\n\n    return res as UserProfile;\n  }\n\n  async authenticate(params: AuthPopUpParams) {\n    await this.window.send(\n      'authentication.authenticate',\n      params.url,\n      params.width,\n      params.height,\n      params.isExternal\n    );\n  }\n\n  async success(result?: string) {\n    await this.window.send('authentication.authenticate.success', result);\n  }\n\n  async failure(reason?: string) {\n    await this.window.send('authentication.authenticate.success', reason);\n  }\n}\n"]}