UNPKG

@azure/msal-browser

Version:
79 lines (76 loc) • 3.78 kB
/*! @azure/msal-browser v5.30.0 2026-11-18 */ 'use strict'; import { ChallengeVerificationStateBaseV2 } from '../../../../core/auth_flow/v2/state/ChallengeVerificationStateBaseV2.mjs'; import { CustomAuthResultV2 } from '../../../../core/auth_flow/v2/CustomAuthResultV2.mjs'; import { CustomAuthError } from '../../../../core/error/CustomAuthError.mjs'; import { UNSUPPORTED_FLOW_TRANSITION } from '../../../../core/network_client/custom_auth_api/v2/ErrorCodesV2.mjs'; import { FLOW_COMPLETED_V2, FLOW_AUTH_METHOD_REGISTRATION_REQUIRED_V2, FLOW_MFA_REQUIRED_V2 } from '../../../../core/interaction_client/v2/result/FlowActionResultV2.mjs'; import { handleExistingAccountVerificationResultV2 } from './ExistingAccountStateTransitionHelperV2.mjs'; /* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ /** * State returned when sign-up discovers an existing account that requires an * email code. Submitting or resending the code preserves existing-account authentication. */ class ExistingAccountCodeRequiredStateV2 extends ChallengeVerificationStateBaseV2 { constructor() { super(...arguments); this.stateType = "existingAccountCodeRequired"; } /** * Submits the existing account's email code and continues authentication. * The result can complete authentication or require enrollment or MFA. * @param code - The email code to verify. * @returns The next existing-account authentication result. */ async submitCode(code) { const { correlationId, logger, continuationState } = this.stateParameters; try { const result = await this.submitCodeCore(code); if (result.type === FLOW_COMPLETED_V2 || result.type === FLOW_AUTH_METHOD_REGISTRATION_REQUIRED_V2 || result.type === FLOW_MFA_REQUIRED_V2) { return handleExistingAccountVerificationResultV2(result, this.stateParameters); } const resultType = result.type; throw new CustomAuthError(UNSUPPORTED_FLOW_TRANSITION, `Existing-account code submission result type '${resultType}' is not supported.`, correlationId); } catch (error) { logger.errorPii(`18e4gg ${error}`, correlationId); return CustomAuthResultV2.createWithError(error, { scenario: continuationState.scenario, correlationId, }); } } /** * Requests a replacement email code for the existing account. The returned * state contains the fresh continuation token and challenge metadata. * @returns The refreshed existing-account code state or an error. */ async resendCode() { const { correlationId, logger, continuationState } = this.stateParameters; try { const result = await this.resendCodeCore(); return new CustomAuthResultV2(new ExistingAccountCodeRequiredStateV2({ ...this.stateParameters, correlationId: result.correlationId, continuationState: result.continuationState, sentTo: result.sentTo, channel: result.channel, codeLength: result.codeLength, }), undefined, result.continuationState.scenario); } catch (error) { logger.errorPii(`011v0m ${error}`, correlationId); return CustomAuthResultV2.createWithError(error, { scenario: continuationState.scenario, correlationId, }); } } } export { ExistingAccountCodeRequiredStateV2 }; //# sourceMappingURL=ExistingAccountCodeRequiredStateV2.mjs.map