@azure/identity 4.7.1-alpha.20250219.1 → 4.7.1-alpha.20250220.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/README.md +3 -1
  2. package/dist/browser/credentials/interactiveBrowserCredential-browser.d.mts.map +1 -1
  3. package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
  4. package/dist/browser/credentials/interactiveBrowserCredential.d.ts +1 -1
  5. package/dist/browser/credentials/interactiveBrowserCredential.js +5 -5
  6. package/dist/browser/credentials/usernamePasswordCredential-browser.d.mts.map +1 -1
  7. package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
  8. package/dist/browser/credentials/usernamePasswordCredential.d.ts +2 -0
  9. package/dist/browser/credentials/usernamePasswordCredential.js +2 -0
  10. package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  11. package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  12. package/dist/browser/msal/browserFlows/msalBrowserCommon.js +235 -60
  13. package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  14. package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  15. package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  16. package/dist/{esm/msal/browserFlows/flows.js → browser/msal/browserFlows/msalBrowserOptions.js} +1 -1
  17. package/dist/browser/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  18. package/dist/commonjs/credentials/usernamePasswordCredential.d.ts +2 -0
  19. package/dist/commonjs/credentials/usernamePasswordCredential.d.ts.map +1 -1
  20. package/dist/commonjs/credentials/usernamePasswordCredential.js +2 -0
  21. package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
  22. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  23. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  24. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +237 -63
  25. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  26. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  27. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  28. package/dist/commonjs/msal/browserFlows/{flows.js → msalBrowserOptions.js} +1 -1
  29. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  30. package/dist/esm/credentials/usernamePasswordCredential.d.ts +2 -0
  31. package/dist/esm/credentials/usernamePasswordCredential.d.ts.map +1 -1
  32. package/dist/esm/credentials/usernamePasswordCredential.js +2 -0
  33. package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
  34. package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  35. package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  36. package/dist/esm/msal/browserFlows/msalBrowserCommon.js +235 -60
  37. package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  38. package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  39. package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  40. package/dist/{browser/msal/browserFlows/flows.js → esm/msal/browserFlows/msalBrowserOptions.js} +1 -1
  41. package/dist/esm/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  42. package/package.json +2 -2
  43. package/dist/browser/msal/browserFlows/flows.d.ts +0 -42
  44. package/dist/browser/msal/browserFlows/flows.d.ts.map +0 -1
  45. package/dist/browser/msal/browserFlows/flows.js.map +0 -1
  46. package/dist/browser/msal/browserFlows/msalAuthCode.d.ts +0 -48
  47. package/dist/browser/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  48. package/dist/browser/msal/browserFlows/msalAuthCode.js +0 -203
  49. package/dist/browser/msal/browserFlows/msalAuthCode.js.map +0 -1
  50. package/dist/commonjs/msal/browserFlows/flows.d.ts +0 -42
  51. package/dist/commonjs/msal/browserFlows/flows.d.ts.map +0 -1
  52. package/dist/commonjs/msal/browserFlows/flows.js.map +0 -1
  53. package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts +0 -48
  54. package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  55. package/dist/commonjs/msal/browserFlows/msalAuthCode.js +0 -208
  56. package/dist/commonjs/msal/browserFlows/msalAuthCode.js.map +0 -1
  57. package/dist/esm/msal/browserFlows/flows.d.ts +0 -42
  58. package/dist/esm/msal/browserFlows/flows.d.ts.map +0 -1
  59. package/dist/esm/msal/browserFlows/flows.js.map +0 -1
  60. package/dist/esm/msal/browserFlows/msalAuthCode.d.ts +0 -48
  61. package/dist/esm/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  62. package/dist/esm/msal/browserFlows/msalAuthCode.js +0 -203
  63. package/dist/esm/msal/browserFlows/msalAuthCode.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"msalBrowserCommon.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAqCrD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA+B;IAE/B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC;IACrD,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAChE,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAA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AM,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACO,YAAY,CACpB,MAAyB,EACzB,MAAmB,EACnB,eAAiC;;QAEjC,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC;QACD,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,kBAAkB,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE;YAC9C,qBAAqB,EAAE,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,EAAE;YAClD,SAAS,EAAE,QAAQ;SACL,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport type { AuthenticationRecord, MsalResult } from \"../types.js\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../../errors.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\nimport { formatSuccess } from \"../../util/logging.js\";\nimport type { MsalFlow, MsalFlowOptions } from \"./flows.js\";\nimport { ensureValidMsalToken, getAuthority, getKnownAuthorities, msalToPublic } from \"../utils.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../../util/tenantIdUtils.js\";\n\nimport type { BrowserLoginStyle } from \"../../credentials/interactiveBrowserCredentialOptions.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { DefaultTenantId } from \"../../constants.js\";\nimport type { LogPolicyOptions } from \"@azure/core-rest-pipeline\";\nimport type { MultiTenantTokenCredentialOptions } from \"../../credentials/multiTenantTokenCredentialOptions.js\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * Some properties might not be used by some flow types.\n */\nexport interface MsalBrowserFlowOptions extends MsalFlowOptions {\n tokenCredentialOptions: MultiTenantTokenCredentialOptions;\n redirectUri?: string;\n loginStyle: BrowserLoginStyle;\n loginHint?: string;\n /**\n * Allows users to configure settings for logging policy options, allow logging account information and personally identifiable information for customer support.\n */\n loggingOptions?: LogPolicyOptions & {\n /**\n * Allows logging account information once the authentication flow succeeds.\n */\n allowLoggingAccountIdentifiers?: boolean;\n /**\n * Allows logging personally identifiable information for customer support.\n */\n enableUnsafeSupportLogging?: boolean;\n };\n}\n\n/**\n * The common methods we use to work with the MSAL browser flows.\n * @internal\n */\nexport interface MsalBrowserFlow extends MsalFlow {\n login(scopes?: string[]): Promise<AuthenticationRecord | undefined>;\n handleRedirect(): Promise<AuthenticationRecord | undefined>;\n}\n\n/**\n * Generates a MSAL configuration that generally works for browsers\n * @internal\n */\nexport function defaultBrowserMsalConfig(\n options: MsalBrowserFlowOptions,\n): msalBrowser.Configuration {\n const tenantId = options.tenantId || DefaultTenantId;\n const authority = getAuthority(tenantId, options.authorityHost);\n return {\n auth: {\n clientId: options.clientId!,\n authority,\n knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableInstanceDiscovery),\n // If the users picked redirect as their login style,\n // but they didn't provide a redirectUri,\n // we can try to use the current page we're in as a default value.\n redirectUri: options.redirectUri || self.location.origin,\n },\n };\n}\n\n/**\n * MSAL partial base client for the browsers.\n *\n * It completes the input configuration with some default values.\n * It also provides with utility protected methods that can be used from any of the clients,\n * which includes handlers for successful responses and errors.\n *\n * @internal\n */\nexport abstract class MsalBrowser implements MsalBrowserFlow {\n protected loginStyle: BrowserLoginStyle;\n protected clientId: string;\n protected tenantId: string;\n protected additionallyAllowedTenantIds: string[];\n protected authorityHost?: string;\n protected account: AuthenticationRecord | undefined;\n protected msalConfig: msalBrowser.Configuration;\n protected disableAutomaticAuthentication?: boolean;\n protected app?: msalBrowser.IPublicClientApplication;\n protected logger: CredentialLogger;\n\n constructor(options: MsalBrowserFlowOptions) {\n this.logger = options.logger;\n this.loginStyle = options.loginStyle;\n if (!options.clientId) {\n throw new CredentialUnavailableError(\"A client ID is required in browsers\");\n }\n this.clientId = options.clientId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.tokenCredentialOptions?.additionallyAllowedTenants,\n );\n this.tenantId = resolveTenantId(this.logger, options.tenantId, options.clientId);\n this.authorityHost = options.authorityHost;\n this.msalConfig = defaultBrowserMsalConfig(options);\n this.disableAutomaticAuthentication = options.disableAutomaticAuthentication;\n\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId,\n };\n }\n }\n\n /**\n * In the browsers we don't need to init()\n */\n async init(): Promise<void> {\n // Nothing to do here.\n }\n\n /**\n * Attempts to handle a redirection request the least amount of times possible.\n */\n public abstract handleRedirect(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Clears MSAL's cache.\n */\n async logout(): Promise<void> {\n this.app?.logout();\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public abstract getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public abstract login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public abstract getTokenSilent(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected abstract doGetToken(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve an authenticated token from MSAL.\n */\n public async getToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n const tenantId =\n processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds) ||\n this.tenantId;\n\n if (!options.authority) {\n options.authority = getAuthority(tenantId, this.authorityHost);\n }\n\n // We ensure that redirection is handled at this point.\n await this.handleRedirect();\n\n if (!(await this.getActiveAccount()) && !this.disableAutomaticAuthentication) {\n await this.login(scopes);\n }\n return this.getTokenSilent(scopes).catch((err) => {\n if (err.name !== \"AuthenticationRequiredError\") {\n throw err;\n }\n if (options?.disableAutomaticAuthentication) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions: options,\n message:\n \"Automatic authentication has been disabled. You may call the authentication() method.\",\n });\n }\n this.logger.info(\n `Silent authentication failed, falling back to interactive method ${this.loginStyle}`,\n );\n return this.doGetToken(scopes);\n });\n }\n\n /**\n * Handles the MSAL authentication result.\n * If the result has an account, we update the local account reference.\n * If the token received is invalid, an error will be thrown depending on what's missing.\n */\n protected handleResult(\n scopes: string | string[],\n result?: MsalResult,\n getTokenOptions?: GetTokenOptions,\n ): AccessToken {\n if (result?.account) {\n this.account = msalToPublic(this.clientId, result.account);\n }\n ensureValidMsalToken(scopes, result, getTokenOptions);\n this.logger.getToken.info(formatSuccess(scopes));\n return {\n token: result.accessToken,\n expiresOnTimestamp: result.expiresOn.getTime(),\n refreshAfterTimestamp: result.refreshOn?.getTime(),\n tokenType: \"Bearer\",\n } as AccessToken;\n }\n}\n"]}
1
+ {"version":3,"file":"msalBrowserCommon.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,WAAW,EAAE,M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as msalBrowser from \"@azure/msal-browser\";\n\nimport type { MsalBrowserFlowOptions } from \"./msalBrowserOptions.js\";\nimport {\n defaultLoggerCallback,\n ensureValidMsalToken,\n getAuthority,\n getKnownAuthorities,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n} from \"../utils.js\";\n\nimport type { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport type { AuthenticationRecord, MsalResult } from \"../types.js\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../../errors.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { getLogLevel } from \"@azure/logger\";\nimport { formatSuccess } from \"../../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../../util/tenantIdUtils.js\";\nimport { DefaultTenantId } from \"../../constants.js\";\n\n/**\n * Generates a MSAL configuration that generally works for browsers\n * @internal\n */\nfunction generateMsalBrowserConfiguration(\n options: MsalBrowserFlowOptions,\n): msalBrowser.Configuration {\n const tenantId = options.tenantId || DefaultTenantId;\n const authority = getAuthority(tenantId, options.authorityHost);\n return {\n auth: {\n clientId: options.clientId!,\n authority,\n knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableInstanceDiscovery),\n // If the users picked redirect as their login style,\n // but they didn't provide a redirectUri,\n // we can try to use the current page we're in as a default value.\n redirectUri: options.redirectUri || self.location.origin,\n },\n cache: {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.\n },\n system: {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(options.logger, \"Browser\"),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n },\n };\n}\n\n/**\n * Methods that are used by InteractiveBrowserCredential\n * @internal\n */\nexport interface MsalBrowserClient {\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n getToken(scopes: string[], options: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport function createMsalBrowserClient(options: MsalBrowserFlowOptions): MsalBrowserClient {\n const loginStyle = options.loginStyle;\n if (!options.clientId) {\n throw new CredentialUnavailableError(\"A client ID is required in browsers\");\n }\n const clientId = options.clientId;\n const logger = options.logger;\n const tenantId = resolveTenantId(logger, options.tenantId, options.clientId);\n const additionallyAllowedTenantIds: string[] = resolveAdditionallyAllowedTenantIds(\n options?.tokenCredentialOptions?.additionallyAllowedTenants,\n );\n const authorityHost = options.authorityHost;\n const msalConfig = generateMsalBrowserConfiguration(options);\n const disableAutomaticAuthentication = options.disableAutomaticAuthentication;\n const loginHint = options.loginHint;\n\n let account: AuthenticationRecord | undefined;\n if (options.authenticationRecord) {\n account = {\n ...options.authenticationRecord,\n tenantId,\n };\n }\n\n // This variable should only be used through calling `getApp` function\n let app: msalBrowser.IPublicClientApplication;\n /**\n * Return the MSAL account if not set yet\n * @returns MSAL application\n */\n async function getApp(): Promise<msalBrowser.IPublicClientApplication> {\n if (!app) {\n // Prepare the MSAL application\n app = await msalBrowser.PublicClientApplication.createPublicClientApplication(msalConfig);\n\n // setting the account right after the app is created.\n if (account) {\n app.setActiveAccount(publicToMsal(account));\n }\n }\n\n return app;\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n async function handleBrowserResult(\n result?: msalBrowser.AuthenticationResult,\n ): Promise<AuthenticationRecord | undefined> {\n try {\n const msalApp = await getApp();\n if (result && result.account) {\n logger.info(`MSAL Browser V2 authentication successful.`);\n msalApp.setActiveAccount(result.account);\n return msalToPublic(clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = msalApp.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const allAccounts = app.getAllAccounts();\n if (allAccounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n logger.info(\n `More than one account was found authenticated for this Client ID and Tenant ID.\n However, no \"authenticationRecord\" has been provided for this credential,\n therefore we're unable to pick between these accounts.\n A new login attempt will be requested, to ensure the correct account is picked.\n To work with multiple accounts for the same Client ID and Tenant ID, please provide an \"authenticationRecord\" when initializing \"InteractiveBrowserCredential\".`,\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await msalApp.logout({\n onRedirectNavigate: () => false,\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (allAccounts.length === 1) {\n const msalAccount = allAccounts[0];\n msalApp.setActiveAccount(msalAccount);\n return msalToPublic(clientId, msalAccount);\n }\n\n logger.info(`No accounts were found through MSAL.`);\n } catch (e: any) {\n logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Handles the MSAL authentication result.\n * If the result has an account, we update the local account reference.\n * If the token received is invalid, an error will be thrown depending on what's missing.\n */\n function handleResult(\n scopes: string | string[],\n result?: MsalResult,\n getTokenOptions?: GetTokenOptions,\n ): AccessToken {\n if (result?.account) {\n account = msalToPublic(clientId, result.account);\n }\n ensureValidMsalToken(scopes, result, getTokenOptions);\n logger.getToken.info(formatSuccess(scopes));\n return {\n token: result.accessToken,\n expiresOnTimestamp: result.expiresOn.getTime(),\n refreshAfterTimestamp: result.refreshOn?.getTime(),\n tokenType: \"Bearer\",\n };\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n async function handleRedirect(): Promise<AuthenticationRecord | undefined> {\n const msalApp = await getApp();\n return handleBrowserResult((await msalApp.handleRedirectPromise(redirectHash)) || undefined);\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n async function getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const msalApp = await getApp();\n const activeAccount = msalApp.getActiveAccount();\n if (!activeAccount) {\n return;\n }\n return msalToPublic(clientId, activeAccount);\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n async function login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest: msalBrowser.RedirectRequest = {\n scopes: arrayScopes,\n loginHint: loginHint,\n };\n const msalApp = await getApp();\n switch (loginStyle) {\n case \"redirect\": {\n await app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return handleBrowserResult(await msalApp.loginPopup(loginRequest));\n }\n }\n\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n async function getTokenSilent(\n scopes: string[],\n getTokenOptions?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const activeAccount = await getActiveAccount();\n if (!activeAccount) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\n message:\n \"Silent authentication failed. We couldn't retrieve an active account from the cache.\",\n });\n }\n\n const parameters: msalBrowser.SilentRequest = {\n authority: getTokenOptions?.authority || msalConfig.auth.authority!,\n correlationId: getTokenOptions?.correlationId,\n claims: getTokenOptions?.claims,\n account: publicToMsal(activeAccount),\n forceRefresh: false,\n scopes,\n };\n\n try {\n logger.info(\"Attempting to acquire token silently\");\n const msalApp = await getApp();\n const response = await msalApp.acquireTokenSilent(parameters);\n return handleResult(scopes, response);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser through interactive methods.\n */\n async function getTokenInteractive(\n scopes: string[],\n getTokenOptions?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const activeAccount = await getActiveAccount();\n if (!activeAccount) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\n message:\n \"Silent authentication failed. We couldn't retrieve an active account from the cache.\",\n });\n }\n\n const parameters: msalBrowser.RedirectRequest = {\n authority: getTokenOptions?.authority || msalConfig.auth.authority!,\n correlationId: getTokenOptions?.correlationId,\n claims: getTokenOptions?.claims,\n account: publicToMsal(activeAccount),\n loginHint: loginHint,\n scopes,\n };\n const msalApp = await getApp();\n switch (loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n\n await msalApp.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0, tokenType: \"Bearer\" };\n case \"popup\":\n return handleResult(scopes, await app.acquireTokenPopup(parameters));\n }\n }\n\n /**\n * Attempts to get token through the silent flow.\n * If failed, get token through interactive method with `doGetToken` method.\n */\n async function getToken(\n scopes: string[],\n getTokenOptions: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n const getTokenTenantId =\n processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds) ||\n tenantId;\n\n if (!getTokenOptions.authority) {\n getTokenOptions.authority = getAuthority(getTokenTenantId, authorityHost);\n }\n\n // We ensure that redirection is handled at this point.\n await handleRedirect();\n\n if (!(await getActiveAccount()) && !disableAutomaticAuthentication) {\n await login(scopes);\n }\n\n // Attempts to get the token silently; else, falls back to interactive method.\n try {\n return await getTokenSilent(scopes, getTokenOptions);\n } catch (err: any) {\n if (err.name !== \"AuthenticationRequiredError\") {\n throw err;\n }\n if (getTokenOptions?.disableAutomaticAuthentication) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\n message:\n \"Automatic authentication has been disabled. You may call the authenticate() method.\",\n });\n }\n logger.info(`Silent authentication failed, falling back to interactive method ${loginStyle}`);\n return getTokenInteractive(scopes, getTokenOptions);\n }\n }\n return {\n getActiveAccount,\n getToken,\n };\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import type { AuthenticationRecord } from "../types.js";
2
+ import type { BrowserLoginStyle } from "../../credentials/interactiveBrowserCredentialOptions.js";
3
+ import type { LogPolicyOptions } from "@azure/core-rest-pipeline";
4
+ import type { MultiTenantTokenCredentialOptions } from "../../credentials/multiTenantTokenCredentialOptions.js";
5
+ import type { CredentialLogger } from "../../util/logging.js";
6
+ /**
7
+ * Options for the MSAL browser flows.
8
+ * @internal
9
+ */
10
+ export interface MsalBrowserFlowOptions {
11
+ logger: CredentialLogger;
12
+ /**
13
+ * The Client ID of the Microsoft Entra application that users will sign into.
14
+ * This parameter is required on the browser.
15
+ */
16
+ clientId?: string;
17
+ /**
18
+ * The Microsoft Entra tenant (directory) ID.
19
+ */
20
+ tenantId?: string;
21
+ /**
22
+ * The authority host to use for authentication requests.
23
+ * Possible values are available through {@link AzureAuthorityHosts}.
24
+ * The default is "https://login.microsoftonline.com".
25
+ */
26
+ authorityHost?: string;
27
+ /**
28
+ * Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.
29
+ * This is necessary to provide in case the application wants to work with more than one account per
30
+ * Client ID and Tenant ID pair.
31
+ *
32
+ * This record can be retrieved by calling to the credential's `authenticate()` method, as follows:
33
+ *
34
+ * const authenticationRecord = await credential.authenticate();
35
+ *
36
+ */
37
+ authenticationRecord?: AuthenticationRecord;
38
+ /**
39
+ * Makes getToken throw if a manual authentication is necessary.
40
+ * Developers will need to call to `authenticate()` to control when to manually authenticate.
41
+ */
42
+ disableAutomaticAuthentication?: boolean;
43
+ /**
44
+ * The field determines whether instance discovery is performed when attempting to authenticate.
45
+ * Setting this to `true` will completely disable both instance discovery and authority validation.
46
+ * As a result, it's crucial to ensure that the configured authority host is valid and trustworthy.
47
+ * This functionality is intended for use in scenarios where the metadata endpoint cannot be reached, such as in private clouds or Azure Stack.
48
+ * The process of instance discovery entails retrieving authority metadata from https://login.microsoft.com/ to validate the authority.
49
+ */
50
+ disableInstanceDiscovery?: boolean;
51
+ /**
52
+ * Options for multi-tenant applications which allows for additionally allowed tenants.
53
+ */
54
+ tokenCredentialOptions: MultiTenantTokenCredentialOptions;
55
+ /**
56
+ * Gets the redirect URI of the application. This should be same as the value
57
+ * in the application registration portal. Defaults to `window.location.href`.
58
+ * This field is no longer required for Node.js.
59
+ */
60
+ redirectUri?: string;
61
+ /**
62
+ * Specifies whether a redirect or a popup window should be used to
63
+ * initiate the user authentication flow. Possible values are "redirect"
64
+ * or "popup" (default) for browser and "popup" (default) for node.
65
+ *
66
+ */
67
+ loginStyle: BrowserLoginStyle;
68
+ /**
69
+ * loginHint allows a user name to be pre-selected for interactive logins.
70
+ * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.
71
+ */
72
+ loginHint?: string;
73
+ /**
74
+ * Allows users to configure settings for logging policy options, allow logging account information and personally identifiable information for customer support.
75
+ */
76
+ loggingOptions?: LogPolicyOptions & {
77
+ /**
78
+ * Allows logging account information once the authentication flow succeeds.
79
+ */
80
+ allowLoggingAccountIdentifiers?: boolean;
81
+ /**
82
+ * Allows logging personally identifiable information for customer support.
83
+ */
84
+ enableUnsafeSupportLogging?: boolean;
85
+ };
86
+ }
87
+ //# sourceMappingURL=msalBrowserOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msalBrowserOptions.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserOptions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wDAAwD,CAAC;AAChH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,gBAAgB,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;OASG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAEzC;;;;;;OAMG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;OAEG;IACH,sBAAsB,EAAE,iCAAiC,CAAC;IAE1D;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,UAAU,EAAE,iBAAiB,CAAC;IAE9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,gBAAgB,GAAG;QAClC;;WAEG;QACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;QACzC;;WAEG;QACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;KACtC,CAAC;CACH"}
@@ -1,4 +1,4 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  export {};
4
- //# sourceMappingURL=flows.js.map
4
+ //# sourceMappingURL=msalBrowserOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msalBrowserOptions.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthenticationRecord } from \"../types.js\";\nimport type { BrowserLoginStyle } from \"../../credentials/interactiveBrowserCredentialOptions.js\";\nimport type { LogPolicyOptions } from \"@azure/core-rest-pipeline\";\nimport type { MultiTenantTokenCredentialOptions } from \"../../credentials/multiTenantTokenCredentialOptions.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\n\n/**\n * Options for the MSAL browser flows.\n * @internal\n */\nexport interface MsalBrowserFlowOptions {\n logger: CredentialLogger;\n\n /**\n * The Client ID of the Microsoft Entra application that users will sign into.\n * This parameter is required on the browser.\n */\n clientId?: string;\n\n /**\n * The Microsoft Entra tenant (directory) ID.\n */\n tenantId?: string;\n\n /**\n * The authority host to use for authentication requests.\n * Possible values are available through {@link AzureAuthorityHosts}.\n * The default is \"https://login.microsoftonline.com\".\n */\n authorityHost?: string;\n\n /**\n * Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.\n * This is necessary to provide in case the application wants to work with more than one account per\n * Client ID and Tenant ID pair.\n *\n * This record can be retrieved by calling to the credential's `authenticate()` method, as follows:\n *\n * const authenticationRecord = await credential.authenticate();\n *\n */\n authenticationRecord?: AuthenticationRecord;\n\n /**\n * Makes getToken throw if a manual authentication is necessary.\n * Developers will need to call to `authenticate()` to control when to manually authenticate.\n */\n disableAutomaticAuthentication?: boolean;\n\n /**\n * The field determines whether instance discovery is performed when attempting to authenticate.\n * Setting this to `true` will completely disable both instance discovery and authority validation.\n * As a result, it's crucial to ensure that the configured authority host is valid and trustworthy.\n * This functionality is intended for use in scenarios where the metadata endpoint cannot be reached, such as in private clouds or Azure Stack.\n * The process of instance discovery entails retrieving authority metadata from https://login.microsoft.com/ to validate the authority.\n */\n disableInstanceDiscovery?: boolean;\n\n /**\n * Options for multi-tenant applications which allows for additionally allowed tenants.\n */\n tokenCredentialOptions: MultiTenantTokenCredentialOptions;\n\n /**\n * Gets the redirect URI of the application. This should be same as the value\n * in the application registration portal. Defaults to `window.location.href`.\n * This field is no longer required for Node.js.\n */\n redirectUri?: string;\n\n /**\n * Specifies whether a redirect or a popup window should be used to\n * initiate the user authentication flow. Possible values are \"redirect\"\n * or \"popup\" (default) for browser and \"popup\" (default) for node.\n *\n */\n loginStyle: BrowserLoginStyle;\n\n /**\n * loginHint allows a user name to be pre-selected for interactive logins.\n * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.\n */\n loginHint?: string;\n\n /**\n * Allows users to configure settings for logging policy options, allow logging account information and personally identifiable information for customer support.\n */\n loggingOptions?: LogPolicyOptions & {\n /**\n * Allows logging account information once the authentication flow succeeds.\n */\n allowLoggingAccountIdentifiers?: boolean;\n /**\n * Allows logging personally identifiable information for customer support.\n */\n enableUnsafeSupportLogging?: boolean;\n };\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/identity",
3
3
  "sdk-type": "client",
4
- "version": "4.7.1-alpha.20250219.1",
4
+ "version": "4.7.1-alpha.20250220.3",
5
5
  "description": "Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID",
6
6
  "main": "./dist/commonjs/index.js",
7
7
  "module": "./dist/esm/index.js",
@@ -86,7 +86,7 @@
86
86
  "@azure/core-tracing": "^1.0.0",
87
87
  "@azure/core-util": "^1.11.0",
88
88
  "@azure/logger": "^1.0.0",
89
- "@azure/msal-node": "^3.2.1",
89
+ "@azure/msal-node": "^3.2.3",
90
90
  "@azure/msal-browser": "^4.2.0",
91
91
  "events": "^3.0.0",
92
92
  "jws": "^4.0.0",
@@ -1,42 +0,0 @@
1
- import type { AccessToken } from "@azure/core-auth";
2
- import type { AuthenticationRecord } from "../types.js";
3
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
4
- import type { CredentialLogger } from "../../util/logging.js";
5
- /**
6
- * Union of the constructor parameters that all MSAL flow types take.
7
- * @internal
8
- */
9
- export interface MsalFlowOptions {
10
- logger: CredentialLogger;
11
- clientId?: string;
12
- tenantId?: string;
13
- authorityHost?: string;
14
- authenticationRecord?: AuthenticationRecord;
15
- disableAutomaticAuthentication?: boolean;
16
- disableInstanceDiscovery?: boolean;
17
- getAssertion?: () => Promise<string>;
18
- enableMsaPassthrough?: boolean;
19
- }
20
- /**
21
- * The common methods we use to work with the MSAL flows.
22
- * @internal
23
- */
24
- export interface MsalFlow {
25
- /**
26
- * Allows for any setup before any request is processed.
27
- */
28
- init(options?: CredentialFlowGetTokenOptions): Promise<void>;
29
- /**
30
- * Tries to load the active account, either from memory or from MSAL.
31
- */
32
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
33
- /**
34
- * Tries to retrieve the token silently using MSAL.
35
- */
36
- getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
37
- /**
38
- * Calls to the implementation's doGetToken method.
39
- */
40
- getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
41
- }
42
- //# sourceMappingURL=flows.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D;;OAEG;IACH,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IAC9D;;OAEG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACjG;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * @internal\n */\nexport interface MsalFlowOptions {\n logger: CredentialLogger;\n clientId?: string;\n tenantId?: string;\n authorityHost?: string;\n authenticationRecord?: AuthenticationRecord;\n disableAutomaticAuthentication?: boolean;\n disableInstanceDiscovery?: boolean;\n getAssertion?: () => Promise<string>;\n enableMsaPassthrough?: boolean;\n}\n\n/**\n * The common methods we use to work with the MSAL flows.\n * @internal\n */\nexport interface MsalFlow {\n /**\n * Allows for any setup before any request is processed.\n */\n init(options?: CredentialFlowGetTokenOptions): Promise<void>;\n /**\n * Tries to load the active account, either from memory or from MSAL.\n */\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n /**\n * Calls to the implementation's doGetToken method.\n */\n getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\n"]}
@@ -1,48 +0,0 @@
1
- import type { MsalBrowserFlowOptions } from "./msalBrowserCommon.js";
2
- import { MsalBrowser } from "./msalBrowserCommon.js";
3
- import type { AccessToken } from "@azure/core-auth";
4
- import type { AuthenticationRecord } from "../types.js";
5
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
6
- /**
7
- * Uses MSAL Browser 2.X for browser authentication,
8
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
9
- * @internal
10
- */
11
- export declare class MSALAuthCode extends MsalBrowser {
12
- private loginHint?;
13
- /**
14
- * Sets up an MSAL object based on the given parameters.
15
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
16
- * which is set to be the active account.
17
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
18
- */
19
- constructor(options: MsalBrowserFlowOptions);
20
- private getApp;
21
- /**
22
- * Loads the account based on the result of the authentication.
23
- * If no result was received, tries to load the account from the cache.
24
- * @param result - Result object received from MSAL.
25
- */
26
- private handleBrowserResult;
27
- /**
28
- * Uses MSAL to handle the redirect.
29
- */
30
- handleRedirect(): Promise<AuthenticationRecord | undefined>;
31
- /**
32
- * Uses MSAL to trigger a redirect or a popup login.
33
- */
34
- login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;
35
- /**
36
- * Uses MSAL to retrieve the active account.
37
- */
38
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
39
- /**
40
- * Attempts to retrieve a token from cache.
41
- */
42
- getTokenSilent(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
43
- /**
44
- * Attempts to retrieve the token in the browser.
45
- */
46
- protected doGetToken(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
47
- }
48
- //# sourceMappingURL=msalAuthCode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AASrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAMvE;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;;;;;OAKG;gBACS,OAAO,EAAE,sBAAsB;YAuB7B,MAAM;IAgBpB;;;;OAIG;YACW,mBAAmB;IAsDjC;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAKxE;;OAEG;IACU,KAAK,CAAC,MAAM,GAAE,MAAM,GAAG,MAAM,EAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAiB7F;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAS1E;;OAEG;IACU,cAAc,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;IA8BvB;;OAEG;cACa,UAAU,CACxB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;CAgCxB"}
@@ -1,203 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import * as msalBrowser from "@azure/msal-browser";
4
- import { MsalBrowser } from "./msalBrowserCommon.js";
5
- import { defaultLoggerCallback, getMSALLogLevel, handleMsalError, msalToPublic, publicToMsal, } from "../utils.js";
6
- import { AuthenticationRequiredError } from "../../errors.js";
7
- import { getLogLevel } from "@azure/logger";
8
- // We keep a copy of the redirect hash.
9
- const redirectHash = self.location.hash;
10
- /**
11
- * Uses MSAL Browser 2.X for browser authentication,
12
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
13
- * @internal
14
- */
15
- export class MSALAuthCode extends MsalBrowser {
16
- /**
17
- * Sets up an MSAL object based on the given parameters.
18
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
19
- * which is set to be the active account.
20
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
21
- */
22
- constructor(options) {
23
- var _a;
24
- super(options);
25
- this.loginHint = options.loginHint;
26
- this.msalConfig.cache = {
27
- cacheLocation: "sessionStorage",
28
- storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.
29
- };
30
- this.msalConfig.system = {
31
- loggerOptions: {
32
- loggerCallback: defaultLoggerCallback(this.logger, "Browser"),
33
- logLevel: getMSALLogLevel(getLogLevel()),
34
- piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
35
- },
36
- };
37
- if (options.authenticationRecord) {
38
- this.account = Object.assign(Object.assign({}, options.authenticationRecord), { tenantId: this.tenantId });
39
- }
40
- }
41
- async getApp() {
42
- if (!this.app) {
43
- // Prepare the MSAL application
44
- this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(this.msalConfig);
45
- // setting the account right after the app is created.
46
- if (this.account) {
47
- this.app.setActiveAccount(publicToMsal(this.account));
48
- }
49
- }
50
- return this.app;
51
- }
52
- /**
53
- * Loads the account based on the result of the authentication.
54
- * If no result was received, tries to load the account from the cache.
55
- * @param result - Result object received from MSAL.
56
- */
57
- async handleBrowserResult(result) {
58
- try {
59
- const app = await this.getApp();
60
- if (result && result.account) {
61
- this.logger.info(`MSAL Browser V2 authentication successful.`);
62
- app.setActiveAccount(result.account);
63
- return msalToPublic(this.clientId, result.account);
64
- }
65
- // If by this point we happen to have an active account, we should stop trying to parse this.
66
- const activeAccount = await this.app.getActiveAccount();
67
- if (activeAccount) {
68
- return msalToPublic(this.clientId, activeAccount);
69
- }
70
- // If we don't have an active account, we try to activate it from all the already loaded accounts.
71
- const accounts = app.getAllAccounts();
72
- if (accounts.length > 1) {
73
- // If there's more than one account in memory, we force the user to authenticate again.
74
- // At this point we can't identify which account should this credential work with,
75
- // since at this point the user won't have provided enough information.
76
- // We log a message in case that helps.
77
- this.logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
78
- However, no "authenticationRecord" has been provided for this credential,
79
- therefore we're unable to pick between these accounts.
80
- A new login attempt will be requested, to ensure the correct account is picked.
81
- To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing "InteractiveBrowserCredential".`);
82
- // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.
83
- // However, we want to avoid kicking the user out of their authentication on the Azure side.
84
- // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.
85
- await app.logout({
86
- onRedirectNavigate: () => false,
87
- });
88
- return;
89
- }
90
- // If there's only one account for this MSAL object, we can safely activate it.
91
- if (accounts.length === 1) {
92
- const account = accounts[0];
93
- app.setActiveAccount(account);
94
- return msalToPublic(this.clientId, account);
95
- }
96
- this.logger.info(`No accounts were found through MSAL.`);
97
- }
98
- catch (e) {
99
- this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);
100
- }
101
- return;
102
- }
103
- /**
104
- * Uses MSAL to handle the redirect.
105
- */
106
- async handleRedirect() {
107
- const app = await this.getApp();
108
- return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);
109
- }
110
- /**
111
- * Uses MSAL to trigger a redirect or a popup login.
112
- */
113
- async login(scopes = []) {
114
- const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
115
- const loginRequest = {
116
- scopes: arrayScopes,
117
- loginHint: this.loginHint,
118
- };
119
- const app = await this.getApp();
120
- switch (this.loginStyle) {
121
- case "redirect": {
122
- await app.loginRedirect(loginRequest);
123
- return;
124
- }
125
- case "popup":
126
- return this.handleBrowserResult(await app.loginPopup(loginRequest));
127
- }
128
- }
129
- /**
130
- * Uses MSAL to retrieve the active account.
131
- */
132
- async getActiveAccount() {
133
- const app = await this.getApp();
134
- const account = app.getActiveAccount();
135
- if (!account) {
136
- return;
137
- }
138
- return msalToPublic(this.clientId, account);
139
- }
140
- /**
141
- * Attempts to retrieve a token from cache.
142
- */
143
- async getTokenSilent(scopes, options) {
144
- const account = await this.getActiveAccount();
145
- if (!account) {
146
- throw new AuthenticationRequiredError({
147
- scopes,
148
- getTokenOptions: options,
149
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
150
- });
151
- }
152
- const parameters = {
153
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
154
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
155
- claims: options === null || options === void 0 ? void 0 : options.claims,
156
- account: publicToMsal(account),
157
- forceRefresh: false,
158
- scopes,
159
- };
160
- try {
161
- this.logger.info("Attempting to acquire token silently");
162
- const app = await this.getApp();
163
- const response = await app.acquireTokenSilent(parameters);
164
- return this.handleResult(scopes, response);
165
- }
166
- catch (err) {
167
- throw handleMsalError(scopes, err, options);
168
- }
169
- }
170
- /**
171
- * Attempts to retrieve the token in the browser.
172
- */
173
- async doGetToken(scopes, options) {
174
- const account = await this.getActiveAccount();
175
- if (!account) {
176
- throw new AuthenticationRequiredError({
177
- scopes,
178
- getTokenOptions: options,
179
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
180
- });
181
- }
182
- const parameters = {
183
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
184
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
185
- claims: options === null || options === void 0 ? void 0 : options.claims,
186
- account: publicToMsal(account),
187
- loginHint: this.loginHint,
188
- scopes,
189
- };
190
- const app = await this.getApp();
191
- switch (this.loginStyle) {
192
- case "redirect":
193
- // This will go out of the page.
194
- // Once the InteractiveBrowserCredential is initialized again,
195
- // we'll load the MSAL account in the constructor.
196
- await app.acquireTokenRedirect(parameters);
197
- return { token: "", expiresOnTimestamp: 0, tokenType: "Bearer" };
198
- case "popup":
199
- return this.handleResult(scopes, await app.acquireTokenPopup(parameters));
200
- }
201
- }
202
- }
203
- //# sourceMappingURL=msalAuthCode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,uCAAuC;AACvC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;AAExC;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,WAAW;IAG3C;;;;;OAKG;IACH,YAAY,OAA+B;;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEnC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG;YACtB,aAAa,EAAE,gBAAgB;YAC/B,sBAAsB,EAAE,IAAI,EAAE,0DAA0D;SACzF,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG;YACvB,aAAa,EAAE;gBACb,cAAc,EAAE,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC;gBAC7D,QAAQ,EAAE,eAAe,CAAC,WAAW,EAAE,CAAC;gBACxC,iBAAiB,EA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YACvB,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC;YAC9B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM;SACP,CAAC;QACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,QAAQ,IAAI,CAAC,UAAU,EAAE,CAAC;YACxB,KAAK,UAAU;gBACb,gCAAgC;gBAChC,8DAA8D;gBAC9D,kDAAkD;gBAElD,MAAM,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;gBAC3C,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;YACnE,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { MsalBrowserFlowOptions } from \"./msalBrowserCommon.js\";\nimport { MsalBrowser } from \"./msalBrowserCommon.js\";\nimport {\n defaultLoggerCallback,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n} from \"../utils.js\";\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport { AuthenticationRequiredError } from \"../../errors.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { getLogLevel } from \"@azure/logger\";\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport class MSALAuthCode extends MsalBrowser {\n private loginHint?: string;\n\n /**\n * Sets up an MSAL object based on the given parameters.\n * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,\n * which is set to be the active account.\n * @param options - Parameters necessary and otherwise used to create the MSAL object.\n */\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n this.loginHint = options.loginHint;\n\n this.msalConfig.cache = {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.\n };\n this.msalConfig.system = {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(this.logger, \"Browser\"),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n };\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId,\n };\n }\n }\n\n private async getApp(): Promise<msalBrowser.IPublicClientApplication> {\n if (!this.app) {\n // Prepare the MSAL application\n this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(\n this.msalConfig as msalBrowser.Configuration,\n );\n\n // setting the account right after the app is created.\n if (this.account) {\n this.app.setActiveAccount(publicToMsal(this.account));\n }\n }\n\n return this.app;\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n private async handleBrowserResult(\n result?: msalBrowser.AuthenticationResult,\n ): Promise<AuthenticationRecord | undefined> {\n try {\n const app = await this.getApp();\n if (result && result.account) {\n this.logger.info(`MSAL Browser V2 authentication successful.`);\n app.setActiveAccount(result.account);\n return msalToPublic(this.clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = await this.app!.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(this.clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const accounts = app.getAllAccounts();\n if (accounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n this.logger.info(\n `More than one account was found authenticated for this Client ID and Tenant ID.\nHowever, no \"authenticationRecord\" has been provided for this credential,\ntherefore we're unable to pick between these accounts.\nA new login attempt will be requested, to ensure the correct account is picked.\nTo work with multiple accounts for the same Client ID and Tenant ID, please provide an \"authenticationRecord\" when initializing \"InteractiveBrowserCredential\".`,\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await app.logout({\n onRedirectNavigate: () => false,\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (accounts.length === 1) {\n const account = accounts[0];\n app.setActiveAccount(account);\n return msalToPublic(this.clientId, account);\n }\n\n this.logger.info(`No accounts were found through MSAL.`);\n } catch (e: any) {\n this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n public async handleRedirect(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public async login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest: msalBrowser.RedirectRequest = {\n scopes: arrayScopes,\n loginHint: this.loginHint,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\": {\n await app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return this.handleBrowserResult(await app.loginPopup(loginRequest));\n }\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public async getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n const account = app.getActiveAccount();\n if (!account) {\n return;\n }\n return msalToPublic(this.clientId, account);\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions: options,\n message:\n \"Silent authentication failed. We couldn't retrieve an active account from the cache.\",\n });\n }\n\n const parameters: msalBrowser.SilentRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n forceRefresh: false,\n scopes,\n };\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n const app = await this.getApp();\n const response = await app.acquireTokenSilent(parameters);\n return this.handleResult(scopes, response);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions: options,\n message:\n \"Silent authentication failed. We couldn't retrieve an active account from the cache.\",\n });\n }\n\n const parameters: msalBrowser.RedirectRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n loginHint: this.loginHint,\n scopes,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n\n await app.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0, tokenType: \"Bearer\" };\n case \"popup\":\n return this.handleResult(scopes, await app.acquireTokenPopup(parameters));\n }\n }\n}\n"]}
@@ -1,42 +0,0 @@
1
- import type { AccessToken } from "@azure/core-auth";
2
- import type { AuthenticationRecord } from "../types.js";
3
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
4
- import type { CredentialLogger } from "../../util/logging.js";
5
- /**
6
- * Union of the constructor parameters that all MSAL flow types take.
7
- * @internal
8
- */
9
- export interface MsalFlowOptions {
10
- logger: CredentialLogger;
11
- clientId?: string;
12
- tenantId?: string;
13
- authorityHost?: string;
14
- authenticationRecord?: AuthenticationRecord;
15
- disableAutomaticAuthentication?: boolean;
16
- disableInstanceDiscovery?: boolean;
17
- getAssertion?: () => Promise<string>;
18
- enableMsaPassthrough?: boolean;
19
- }
20
- /**
21
- * The common methods we use to work with the MSAL flows.
22
- * @internal
23
- */
24
- export interface MsalFlow {
25
- /**
26
- * Allows for any setup before any request is processed.
27
- */
28
- init(options?: CredentialFlowGetTokenOptions): Promise<void>;
29
- /**
30
- * Tries to load the active account, either from memory or from MSAL.
31
- */
32
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
33
- /**
34
- * Tries to retrieve the token silently using MSAL.
35
- */
36
- getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
37
- /**
38
- * Calls to the implementation's doGetToken method.
39
- */
40
- getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
41
- }
42
- //# sourceMappingURL=flows.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D;;OAEG;IACH,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IAC9D;;OAEG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACjG;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * @internal\n */\nexport interface MsalFlowOptions {\n logger: CredentialLogger;\n clientId?: string;\n tenantId?: string;\n authorityHost?: string;\n authenticationRecord?: AuthenticationRecord;\n disableAutomaticAuthentication?: boolean;\n disableInstanceDiscovery?: boolean;\n getAssertion?: () => Promise<string>;\n enableMsaPassthrough?: boolean;\n}\n\n/**\n * The common methods we use to work with the MSAL flows.\n * @internal\n */\nexport interface MsalFlow {\n /**\n * Allows for any setup before any request is processed.\n */\n init(options?: CredentialFlowGetTokenOptions): Promise<void>;\n /**\n * Tries to load the active account, either from memory or from MSAL.\n */\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n /**\n * Calls to the implementation's doGetToken method.\n */\n getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\n"]}