Skip to content

Native Auth V2 entry and validation fixes - #8898

Merged
Yongdi Wang (yongdiw) merged 21 commits into
devfrom
yongdi/native-auth-v2-fixes
Oct 20, 2026
Merged

Yongdi Wang (yongdiw) merged 21 commits into
devfrom
yongdi/native-auth-v2-fixes

Conversation

@yongdiw

@yongdiw Yongdi Wang (yongdiw) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Finalizes Native Auth V2 entry-request and input-validation behavior.

  • Defines explicit input types for V2 sign-in, sign-up, and reset-password, including optional scopes and claims, and normalizes requested scopes with the required OpenID scopes.
  • Keeps continuation signIn() parameterless. Token redemption uses the server continuation, and MSAL uses the normalized entry scopes only when the token response omits its scope value.
  • Continues with email-code authentication when a password was supplied but the service offers email verification instead of a password method.
  • Accepts any non-empty verification-code string and lets the service validate the expected code length.
  • Updates the controller/API wiring, release metadata, ownership, and unit/integration coverage for the finalized behavior.

Yongdi Wang (yongdiw) and others added 4 commits October 12, 2026 15:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Explicit null continuation scopes behave incorrectly, runtime OTP type validation is lost, and required release documentation is missing.

5 open findings
What changed in this PR

Adds Native Auth V2 authorization inputs, continuation-scope retention, email fallback, and server-side OTP validation.

Changes:

  • Propagates and validates V2 scopes and claims.
  • Falls back from unavailable password authentication to email OTP.
  • Delegates OTP length validation to the service and expands tests.
File Description
SignUpV2.spec.ts Tests claims/scopes propagation and validation.
SignInV2.spec.ts Tests entry inputs, email fallback, and OTP handling.
ResetPasswordV2.spec.ts Tests retained scopes and server OTP validation.
ArgumentValidator.spec.ts Tests string-array validation.
CustomAuthApiClientV2.spec.ts Tests authorization form fields.
FlowInteractionClientV2.spec.ts Tests flow propagation and routing.
MFAVerificationRequiredStateV2.spec.ts Tests wrong-length MFA submission.
CodeRequiredStateV2.spec.ts Tests empty and short OTP submission.
SignInContinuationStateV2.ts Retains or overrides continuation scopes.
CustomAuthActionInputs.ts Extends V2 public input types.
ArgumentValidator.ts Adds string-array validation.
RequestsV2.ts Adds claims to authorization requests.
BaseApiClientV2.ts Serializes scopes and claims.
FlowParamsV2.ts Propagates entry request parameters.
InteractionClientBaseV2.ts Supports nullable scopes.
FlowInteractionClientV2.ts Implements propagation and email fallback.
ChallengeVerificationStateBaseV2.ts Removes client-side OTP length enforcement.
CustomAuthStandardController.ts Validates and forwards V2 inputs.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Yongdi Wang (yongdiw) and others added 2 commits October 12, 2026 15:40
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Stop carrying entry scopes and claims through continuation state or the authorization-code token request. Use the token response scope for cache processing and update V2 flow coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Remove obsolete token request scopes from the PR1 MFA state tests after continuation state stopped retaining scopes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6

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.

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.

Yongdi Wang (yongdiw) and others added 2 commits October 15, 2026 19:37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Yongdi Wang (yongdiw) and others added 2 commits October 19, 2026 14:42
## Summary

Unifies Native Auth V2 authentication-method selection and makes
challenge transitions result-driven.

- Replaces separate primary and MFA selection surfaces with
`AuthMethodSelectionRequiredStateV2.selectAuthMethod()` and one public
request-challenge result.
- Maps the trusted returned challenge to the correct state: selected
single-factor password to `PasswordRequiredStateV2`, selected email/SMS
code to `CodeRequiredStateV2`, and selected MFA code to
`MFAVerificationRequiredStateV2`; unsupported combinations fail
explicitly.
- Preserves the sign-in transition handler through selected primary
password and code states so verification can complete sign-in or advance
to MFA.
- Centralizes sign-in state transitions, adds the shared first-factor
resend result, and removes redundant MFA-specific selection state and
result exports.
- Reorganizes the V2 sign-in/reset integration suites and adds focused
state and transition regression coverage.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a64bca42-c756-4466-849e-4038c47bedb6
Populate innerErrorCode instead of subError for invalid OTP and weak-password fixtures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bb74294c-cf5f-4dbe-9db6-7889fce967e9
@yongdiw
Yongdi Wang (yongdiw) merged commit a9a1221 into dev Oct 20, 2026
@yongdiw
Yongdi Wang (yongdiw) deleted the yongdi/native-auth-v2-fixes branch October 20, 2026 09:22
Disha Janardhan (djanardhan98) added a commit to AzureAD/microsoft-authentication-library-common-for-android that referenced this pull request Oct 20, 2026
)

## Summary

Port Common Native Auth V2 authorize-request inputs and related OTP
parity from AzureAD/microsoft-authentication-library-for-js#8898.

- Build on the existing authorize-challenge scope serialization and add
initial claims propagation.
- Include default OIDC scopes for sign-in, sign-up, and reset;
canonicalize only recognized OIDC defaults while preserving resource
scopes.
- Preserve entry scopes for absent continuation inputs and honor
explicitly empty continuation inputs.
- Exclude claims from token serialization while retaining local
metadata; keep scopes on token requests.
- Allow empty OTP values to reach service validation and preserve
existing password-to-email fallback and V1 behavior.

**Approved wire policy:** scopes and optional claims at initial
authorize-challenge, scopes without claims at token exchange, neither on
other intermediate requests. This intentionally follows JS behavior
rather than the work item's literal entry-only scope wording.

Fixes
[AB#3784690](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3784690)

## Dependencies

Stacked on the separate Common unified-errors PR:
#3307. Its
base is the errors branch so the workstream diff stays isolated.
Consumed by the paired MSAL authorize-inputs PR:
AzureAD/microsoft-authentication-library-for-android#2619.
Merge the errors dependency first, then retarget this PR to `dev`.

## Validation

Scopes/claims snapshot: **661 selected unit tests passed** (218 MSAL,
349 Common4j, 94 Common Android), with zero failures, errors, or skips
in the final XML reports.
Coverage includes all three initial entries and token paths, claims wire
encoding, continuation scope retention/override, canonical OIDC defaults
with preserved resource casing/duplicates, empty OTP submission, and
standalone V1 regressions.
Final integrated-stack PR2601 validation: **20 live signup/reset E2E
tests and 4 recorder tests passed**, with 3 known duplicate-account
service-test skips. One Mail.tm `/accounts` HTTP 429 attempt passed on
the existing automatic retry; no assertions or retry configuration were
changed.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Silviu Petrescu <spetrescu@microsoft.com>
Copilot-Session: 0bcd671b-73fa-4ee6-bcd6-65d7eea4d753
Copilot-Session: eafe5634-2142-4235-a7dc-d26bc1baa0d5
Disha Janardhan (djanardhan98) added a commit to AzureAD/microsoft-authentication-library-for-android that referenced this pull request Oct 21, 2026
## Summary

Port Android Native Auth V2 authorize-request inputs and related OTP
parity from AzureAD/microsoft-authentication-library-for-js#8898.

- Accept optional scopes and typed claims for sign-up and password
reset, and propagate inputs for all three V2 entry points.
- Snapshot callback inputs and preserve existing cancellation, callback
delivery, and password clearing.
- Preserve entry scopes when continuation scopes are absent; allow
explicitly empty continuation scopes to select default OIDC scopes.
- Submit empty/short first-factor and MFA OTPs to the service for
validation rather than reject them locally.
- Preserve Native Auth V1 behavior and existing password-to-email
fallback.

**Approved wire policy:** send scopes and optional claims on the initial
authorize-challenge; send scopes but no claims on token exchange.
Intermediate requests send neither. This intentionally follows JS
behavior rather than the work item's literal entry-only scope wording.

Fixes
[AB#3784690](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3784690)

## Dependencies

Stacked on the separate MSAL unified-errors PR:
#2618. Its base is
the errors branch so this diff contains only the scopes/claims
workstream.
Requires the paired Common authorize-inputs PR:
AzureAD/microsoft-authentication-library-common-for-android#3308.
The Common gitlink points to `b41473a29fd7e519108b0630526e652996e38f9f`.
Merge the errors dependencies first, then retarget this PR to `dev`.

## Validation

Scopes/claims snapshot: **661 selected unit tests passed** (218 MSAL,
349 Common4j, 94 Common Android), with zero failures, errors, or skips
in the final XML reports.
Coverage includes all three initial entries, callback input snapshots,
continuation scope retention/override, canonical OIDC defaults on entry
and token requests, empty/short OTP service submission, and standalone
V1 regressions.
Final integrated-stack PR2601 validation: **20 live signup/reset E2E
tests and 4 recorder tests passed**, with 3 known duplicate-account
service-test skips. One Mail.tm `/accounts` HTTP 429 attempt passed on
the existing automatic retry; no assertions or retry configuration were
changed.

The live fixture overlay comes from
#2601 and is not
included in this feature PR.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0bcd671b-73fa-4ee6-bcd6-65d7eea4d753
Copilot-Session: 55791345-e680-4927-a364-f6de503184be
Copilot-Session: 495388ac-9812-45ec-9120-b110dcbe5903
Copilot-Session: eafe5634-2142-4235-a7dc-d26bc1baa0d5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants