Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2e88a03
Add scopes and claims to V2 authorization entry
yongdiw Oct 8, 2026
915ab7d
Allow email fallback for V2 password input
yongdiw Oct 9, 2026
29c0f2f
Remove V2 code-length validation
yongdiw Oct 9, 2026
a1f023c
Fix Native Auth V2 formatting
yongdiw Oct 12, 2026
7acba6e
Add changefile for Native Auth V2 fixes
yongdiw Oct 12, 2026
d3bafde
update CODEOWNERS
yongdiw Oct 12, 2026
b74b901
Update changefile author email
yongdiw Oct 12, 2026
dc41a62
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 12, 2026
236ed56
Remove inputs from V2 continuation sign-in
yongdiw Oct 12, 2026
29af15d
Update V2 MFA continuation fixtures
yongdiw Oct 12, 2026
d101e31
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 13, 2026
b90f6fd
Fix native auth V2 token response scope fallback
yongdiw Oct 14, 2026
cf87471
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 14, 2026
1a4e3cb
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 14, 2026
d1812dd
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 14, 2026
8a30db9
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 15, 2026
47fdcbc
Define Native Auth V2 entry inputs explicitly
yongdiw Oct 15, 2026
0f2dffb
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 15, 2026
074bb69
Merge branch 'dev' into yongdi/native-auth-v2-fixes
yongdiw Oct 19, 2026
c8b7661
Unify Native Auth V2 authentication method selection (#8899)
yongdiw Oct 19, 2026
c6d8235
Fix Native Auth V2 error mocks in state tests
yongdiw Oct 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
* @AzureAD/msal-js-public-client

# MSAL Browser
/lib/msal-browser/src/custom_auth/ @shenj @yongdiw @nilo-ms @spetrescu84 @mustafamizrak
/lib/msal-browser/test/custom_auth/ @shenj @yongdiw @nilo-ms @spetrescu84 @mustafamizrak
/samples/msal-browser-samples/NativeAuthSample @shenj @yongdiw @spetrescu84 @mustafamizrak
/lib/msal-browser/src/custom_auth/ @shenj @yongdiw @spetrescu84 @antrix1989
/lib/msal-browser/test/custom_auth/ @shenj @yongdiw @spetrescu84 @antrix1989
/samples/msal-browser-samples/NativeAuthSample @shenj @yongdiw @spetrescu84 @antrix1989

# MSAL Node
/lib/msal-node/ @AzureAD/msal-js-public-client @AzureAD/id4s-msal-team
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add Native Auth V2 authorization inputs and challenge validation fixes [#8898](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8898)",
"packageName": "@azure/msal-browser",
"email": "yongdiwang@microsoft.com",
"dependentChangeType": "patch"
}
13 changes: 8 additions & 5 deletions lib/msal-browser/src/custom_auth/CustomAuthActionInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ export type SignInWithContinuationTokenInputs = {
claims?: string;
};

export type SignInInputsV2 = SignInInputs;
export type SignInInputsV2 = Omit<SignInInputs, "scopes"> & {
scopes?: Array<string> | null;
Comment thread
spetrescu84 marked this conversation as resolved.
Resolved
};
Comment thread
yongdiw marked this conversation as resolved.
Resolved

export type ResetPasswordInputsV2 = ResetPasswordInputs;
export type ResetPasswordInputsV2 = ResetPasswordInputs & {
scopes?: Array<string> | null;
claims?: string;
};
Comment thread
yongdiw marked this conversation as resolved.
Resolved

export type SignUpInputsV2 = SignUpInputs & {
scopes?: Array<string>;
scopes?: Array<string> | null;
claims?: string;
};

export type SignInContinuationInputsV2 = SignInWithContinuationTokenInputs;
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,20 @@ export class CustomAuthStandardController
inputs.username,
correlationId
);
if (inputs.scopes !== undefined && inputs.scopes !== null) {
ArgumentValidator.ensureArgumentIsStringArray(
"inputs.scopes",
inputs.scopes,
correlationId
);
}
if (inputs.claims) {
ArgumentValidator.ensureArgumentIsJSONString(
"inputs.claims",
inputs.claims,
correlationId
);
}
this.ensureUserNotSignedIn(correlationId);

this.logger.verbose(
Expand All @@ -662,6 +676,8 @@ export class CustomAuthStandardController
const result = await this.flowClientV2.resetPassword({
correlationId,
username: inputs.username,
scopes: inputs.scopes,
claims: inputs.claims,
});

this.logger.verbose(
Expand Down Expand Up @@ -729,6 +745,13 @@ export class CustomAuthStandardController
inputs.username,
correlationId
);
if (inputs.scopes !== undefined && inputs.scopes !== null) {
ArgumentValidator.ensureArgumentIsStringArray(
"inputs.scopes",
inputs.scopes,
correlationId
);
}
if (inputs.claims) {
ArgumentValidator.ensureArgumentIsJSONString(
"inputs.claims",
Expand All @@ -748,6 +771,7 @@ export class CustomAuthStandardController
username: inputs.username,
password: inputs.password,
scopes: inputs.scopes,
claims: inputs.claims,
});

if (result.type === FLOW_COMPLETED_V2) {
Expand Down Expand Up @@ -858,6 +882,20 @@ export class CustomAuthStandardController
correlationId
);
}
if (inputs.scopes !== undefined && inputs.scopes !== null) {
ArgumentValidator.ensureArgumentIsStringArray(
"inputs.scopes",
inputs.scopes,
correlationId
);
}
if (inputs.claims) {
ArgumentValidator.ensureArgumentIsJSONString(
"inputs.claims",
inputs.claims,
correlationId
);
}
this.ensureUserNotSignedIn(correlationId);

this.logger.verbose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
FlowCodeRequiredResultV2,
FlowSubmitCodeResultV2,
} from "../../../interaction_client/v2/result/FlowActionResultV2.js";
import { ensureArgumentIsNotNullOrUndefined } from "../../../utils/ArgumentValidator.js";

export abstract class ChallengeVerificationStateBaseV2<
TParameters extends CodeVerificationStateParametersV2 = CodeVerificationStateParametersV2
Expand All @@ -33,9 +34,11 @@ export abstract class ChallengeVerificationStateBaseV2<
protected async submitCodeCore(
code: string
): Promise<FlowSubmitCodeResultV2> {
if (this.codeLength) {
this.ensureCodeIsValid(code, this.codeLength);
}
ensureArgumentIsNotNullOrUndefined(
"code",
code,
this.stateParameters.correlationId
);
Comment thread
yongdiw marked this conversation as resolved.
Resolved

return this.stateParameters.flowClient.submitCode({
correlationId: this.stateParameters.correlationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export interface FlowContinuationStateV2 {
continuationToken: string;
scenario: CustomAuthFlowScenarioV2;
links: FlowLinksV2;
tokenRequest?: {
scopes?: string[];
};
signUp?: {
passwordWasSupplied: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {

this.logger.verbose("Starting V2 sign-in.", correlationId);

const scopes = this.getScopes(parameters.scopes);
const entryResult = await this.apiClient.authorizeChallengeStart(
context
context,
scopes,
parameters.claims
);
const startResult = await this.apiClient.signInStart(
this.requireLink(correlationId, entryResult.signInHref, {
Expand All @@ -168,9 +171,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken: startResult.continuationToken,
scenario: CustomAuthFlowScenarioV2.SignIn,
links: {},
tokenRequest: {
scopes: parameters.scopes,
},
};
const methods = startResult.methods.map((method) => ({
id: method.id,
Expand Down Expand Up @@ -231,9 +231,11 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {

this.logger.verbose("Starting V2 sign-up.", correlationId);

const scopes = this.getScopes(parameters.scopes);
const entryResult = await this.apiClient.authorizeChallengeStart(
context,
parameters.scopes
scopes,
parameters.claims
);
const startResult = await this.apiClient.signUpStart(
this.requireLink(correlationId, entryResult.signUpHref, {
Expand Down Expand Up @@ -269,9 +271,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken: startResult.continuationToken,
scenario: CustomAuthFlowScenarioV2.SignUp,
links: {},
tokenRequest: {
scopes: parameters.scopes,
},
signUp: {
passwordWasSupplied: attributes.password !== undefined,
},
Expand Down Expand Up @@ -318,8 +317,11 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
correlationId
);

const scopes = this.getScopes(parameters.scopes);
const entryResult = await this.apiClient.authorizeChallengeStart(
context
context,
scopes,
parameters.claims
);
const startResult = await this.apiClient.resetPasswordStart(
this.requireLink(correlationId, entryResult.resetPasswordHref, {
Expand Down Expand Up @@ -520,7 +522,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
links: {
submitAttributes: verifyResult.submitAttributesHref,
},
tokenRequest: continuationState.tokenRequest,
signUp: continuationState.signUp,
};
const attributes = verifyResult.attributes.filter(
Expand Down Expand Up @@ -557,7 +558,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken: verifyResult.continuationToken,
scenario: continuationState.scenario,
links: {},
tokenRequest: continuationState.tokenRequest,
},
});
}
Expand Down Expand Up @@ -756,19 +756,15 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
correlationId
);

const scopes = this.getScopes(parameters.scopes);

const tokenResponse = await this.apiClient.completeWithTokens(
{
continuationToken: continuationState.continuationToken,
scopes,
},
context
);

const authenticationResult = await this.handleTokenResponse(
tokenResponse,
scopes,
correlationId,
apiId
);
Expand Down Expand Up @@ -803,7 +799,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken: verifyResult.continuationToken,
scenario: continuationState.scenario,
links: {},
tokenRequest: continuationState.tokenRequest,
},
methods: verifyResult.methods.map((method) => ({
id: method.id,
Expand Down Expand Up @@ -846,22 +841,9 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
method.type.toLowerCase() === AuthenticationMethodTypeV2.EMAIL
);

if (passwordProvided) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say removing this is ok, they will catch on fast when they see the code being sent. Also it's big UI ibug if they have password there but use it for OTP users

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The stacked method-selection PR #8899 removes this automatic choice when multiple supported methods are returned and lets the application select the actual method. A supplied password is submitted automatically only when Password is the sole supported method; if Email/SMS is the sole method, the SDK returns code-required and ignores the supplied password. Focused unit coverage verifies the supplied-password + Email OTP case.

if (passwordMethod) {
return passwordMethod;
}

const message =
"A password was supplied, but the sign-in response did not include a password method.";
this.logger.error(message, correlationId);
throw new CustomAuthError(
UNSUPPORTED_FLOW_TRANSITION,
message,
correlationId
);
}

const selectedMethod = emailMethod ?? passwordMethod;
const selectedMethod = passwordProvided
? passwordMethod ?? emailMethod
: emailMethod ?? passwordMethod;
if (selectedMethod) {
return selectedMethod;
}
Expand Down Expand Up @@ -893,7 +875,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
verify: result.verifyHref,
resend: result.resendHref,
},
tokenRequest: continuationState.tokenRequest,
signUp: continuationState.signUp,
},
channel: result.type,
Expand All @@ -917,7 +898,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
links: {
submitAttributes: result.submitAttributesHref,
},
tokenRequest: continuationState.tokenRequest,
signUp: continuationState.signUp,
};
const attributes = result.attributes.filter(
Expand Down Expand Up @@ -951,7 +931,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken: result.continuationToken,
scenario: continuationState.scenario,
links: {},
tokenRequest: continuationState.tokenRequest,
},
});
}
Expand Down Expand Up @@ -1020,9 +999,7 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
continuationToken,
scenario: continuationState.scenario,
links: {},
tokenRequest: continuationState.tokenRequest,
},
scopes: continuationState.tokenRequest?.scopes,
});
}

Expand Down Expand Up @@ -1094,9 +1071,6 @@ export class FlowInteractionClientV2 extends InteractionClientBaseV2 {
challengeResult.resendHref ??
continuationState.links.resend,
},
...(continuationState.tokenRequest && {
tokenRequest: continuationState.tokenRequest,
}),
...(continuationState.signUp && {
signUp: continuationState.signUp,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export abstract class InteractionClientBaseV2 extends StandardInteractionClient
throw new MethodNotImplementedError("InteractionClientBaseV2.logout");
}

protected getScopes(scopes: string[] | undefined): string[] {
protected getScopes(scopes: string[] | null | undefined): string[] {
const requestedScopes = scopes?.filter((scope) => !!scope) ?? [];
const seenScopes = new Set(
requestedScopes.map((scope) => scope.toLowerCase())
Expand All @@ -108,13 +108,15 @@ export abstract class InteractionClientBaseV2 extends StandardInteractionClient

protected async handleTokenResponse(
tokenResponse: TokenResponseV2,
requestScopes: string[],
correlationId: string,
apiId: number
): Promise<AuthenticationResult> {
this.logger.verbose("Processing V2 token response.", correlationId);

const requestTimestamp = Math.round(new Date().getTime() / 1000.0);
const responseScopes = tokenResponse.scope
.split(" ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve the fallback for token responses that omit scope? OAuth allows omission when the granted scopes match the requested scopes (RFC 6749 section 5.1), and ensureTokenResponseIsValid() only checks for access_token. Such a response now throws at .split() before caching, turning successful authentication into a failed result. Previously, the shared response handler fell back to the requested scopes. Please retain the normalized entry scopes as local continuation metadata and use them when the response omits scope, without sending them again on /token. A completion test with a valid token response lacking scope would cover this regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. OAuth token responses may omit scope when the granted scopes are identical to the requested scopes. Before the V2 refactor, the normalized scopes from getScopes() were passed into token handling and used as the fallback.

I restored that behavior by retaining the normalized entry scopes as internal continuation metadata. If the token response includes scope, that value takes precedence; otherwise, token processing uses the retained requested scopes. The authorization-code /token request remains unchanged and still sends only the continuation token—scopes and claims are not included.

I also added tests covering the missing-scope fallback, response-scope precedence, and the /token request payload.

.filter((scope) => !!scope);

const result =
await this.tokenResponseHandler.handleServerTokenResponse(
Expand All @@ -124,7 +126,7 @@ export abstract class InteractionClientBaseV2 extends StandardInteractionClient
{
authority: this.customAuthAuthority.canonicalAuthority,
correlationId,
scopes: requestScopes,
scopes: responseScopes,
},
apiId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ interface FlowParamsBaseV2 {
// Begin a reset for the given account.
export interface FlowStartParamsV2 extends FlowParamsBaseV2 {
username: string;
scopes?: string[] | null;
claims?: string;
}

export interface FlowSignInStartParamsV2 extends FlowStartParamsV2 {
password?: string;
scopes?: string[];
}

export interface FlowSignUpStartParamsV2 extends FlowStartParamsV2 {
password?: string;
attributes?: UserAccountAttributes;
scopes?: string[];
claims?: string;
}

// Request the challenge for the selected method, sending the one-time code to it.
Expand Down Expand Up @@ -62,5 +61,4 @@ export interface FlowSubmitSignUpAttributesParamsV2 extends FlowParamsBaseV2 {
// Sign the account in by redeeming a completed flow's continuation for tokens.
export interface FlowSignInWithContinuationParamsV2 extends FlowParamsBaseV2 {
Comment thread
spetrescu84 marked this conversation as resolved.
Resolved
continuationState: FlowContinuationStateV2;
scopes?: string[];
}
Loading