Skip to content

Refactor Native Auth V2 state inheritance, Fixes AB#3739969 - #2614

Merged
Silviu Petrescu (spetrescu84) merged 4 commits into
devfrom
djanardhan/native-auth-v2-state-hierarchy
Oct 8, 2026
Merged

Silviu Petrescu (spetrescu84) merged 4 commits into
devfrom
djanardhan/native-auth-v2-state-hierarchy

Conversation

@djanardhan98

@djanardhan98 Disha Janardhan (djanardhan98) commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactor Native Auth V2 state inheritance so V2 states do not inherit the V1 continuation-token placeholder, addressing

  • Leave V1 BaseState unchanged, including its hierarchy, constructor, declared virtual getters, continuation-token behavior, and parcel prefix.
  • Have NativeAuthBaseStateV2 implement State and Parcelable directly, owning its correlation ID and opaque continuation state without introducing a shared V1/V2 superclass.
  • Remove the unused raw-token property, constructor arguments, and parcel slot from every V2 state.
  • Keep the opaque Common-owned NativeAuthV2ContinuationState unchanged.
  • Leave authentication transitions, command mapping, errors, callbacks, cancellation, and public flow methods unchanged.

Compatibility and scope

V2 has not shipped, so the V2 hierarchy and parcel layout are intentionally updated without a legacy-format reader or token placeholder. V1 BaseStates.kt is identical to the merge-base version. No new shared public abstraction is introduced.

This is an MSAL-only change. No Common changes or submodule updates are required. Azure Boards linking and work-item updates are intentionally deferred at the author's request.

Coverage

  • Regression tests reject inheritance of V1's raw-token contract and verify that V2 parcels start with correlation metadata.
  • A hierarchy assertion checks that V1 BaseState and NativeAuthBaseStateV2 both extend Object directly.
  • All twelve V2 concrete states are covered by marshalled/unmarshalled parcel round trips.
  • All ten continuation-bearing V2 states preserve their opaque Common DTO; authentication-method lists and serializable Native Auth configuration fields survive restoration.
  • Saved-instance-state Bundle restoration is exercised through code submission, password update, and post-reset sign-in, with runtime configuration explicitly reinitialized.
  • V1 raw-token access and parcel-prefix behavior remain covered.

Validation

Latest simplification (2905a5bb4)

git diff --check passed, and V1 BaseStates.kt was verified unchanged relative to the merge base.

The new hierarchy test and the scoped V2/command-parameter suite were attempted locally, but dependency resolution blocked compilation: the NewAndroid Maven feed returned HTTP 401 for AndroidX and AAPT2 dependencies. An offline retry also failed because those dependencies were not cached. No passing test result is claimed for this commit; the new hierarchy assertion has not been executed.

Earlier refactor validation (before the latest simplification)

The previous PR description recorded 210 targeted tests passed with zero failures using:

gradlew.bat :msal:testLocalDebugUnitTest --tests "com.microsoft.identity.nativeauth.v2.*" --tests "com.microsoft.identity.client.CommandParametersTest" -PmockApiUrl=https://contoso.com/ -PuseMockApiForNativeAuth=true --console=plain --quiet

The earlier scoped code review found no correctness, API, or Parcelable regressions. These results predate 2905a5bb4 and do not validate the latest simplification.

Earlier local live Native Auth V2 E2E verification

On October 5, 2026, the exact test sources from PR 2601 (commit d579ac981b1740987fa3a57e187d1af80a6fda1f) were temporarily overlaid onto this PR's refactor commit 5c9a56871e78dacaf4d98e4f0755cbecc7f06d88 and run locally against live services, not the mock API.

Suite Passed
Email OTP sign-up (SignUpV2EmailOTPTest) 8/8
Email/password sign-up (SignUpV2EmailPasswordTest) 7/7
Self-service password reset (SSPRV2Test) 5/5
Request-recorder unit tests (NativeAuthRequestRecorderTest) 4/4

All 20 live E2E scenarios and all 4 recorder unit tests passed, with zero failures, errors, or skipped tests. Counts were verified from fresh JUnit XML reports, not just the Gradle exit code.

The local run used :msal:testLocalDebugUnitTest with explicit selectors for the four suites above, -Plabtest to enable network tests, and -PuseMockApiForNativeAuth=false. The existing local Native Auth configuration was used; emailProviderPassword from local Gradle properties was supplied to the test worker as EMAIL_PROVIDER_PASSWORD without exposing the value.

This is historical local verification, not a claim that these tests ran in the pipeline or on the latest simplification. The temporary test overlay and local credential bridge were removed afterward; this PR includes no additional E2E test files or credentials.

Existing limitations, unchanged by this refactor

  • NativeAuthPublicClientApplicationConfiguration serializes its own fields, but its non-serializable superclass configuration fields, Android Context, and token cache are not retained. The saved-state continuation test explicitly reinitializes these dependencies and does not claim automatic recovery of runtime configuration. The opaque continuation DTO itself is restored rather than replaced.
  • The broader V1 application integration suites require a configured Native Auth mock service. They were previously attempted, but a missing/placeholder mock endpoint produced fixture-initialization or non-JSON-response failures. Those service-backed suites were not successfully validated here; no changes to their tests or production behavior are included.

AB#3739969

Separate shared correlation metadata from the V1 raw-token contract. Remove V2 token placeholders and their parcel slot without changing authentication flows or the opaque Common continuation state.

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

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

@djanardhan98 Disha Janardhan (djanardhan98) added the changelog:none No changelog entry or version increment is required. label Oct 5, 2026
@djanardhan98 Disha Janardhan (djanardhan98) changed the title Refactor Native Auth V2 state inheritance Refactor Native Auth V2 state inheritance, Fixes AB#3739969 Oct 5, 2026

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Refactors Native Auth V2 state inheritance to remove the legacy V1 raw continuation-token contract from V2 states while preserving V1 behavior, and updates unit tests to validate the new parcel layout and saved-state restoration behavior.

Changes:

  • Introduces a correlation-only NativeAuthState base and moves V2 states off BaseState (V1 raw-token contract).
  • Removes the V2 raw-token placeholder from constructors/parcels and updates V2 state Parcelable read/write expectations.
  • Expands/updates tests to verify V2 parcel prefix, round-trip parcelability for all V2 states, and Bundle saved-instance-state restoration with configuration reinitialization.
File Description
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​BaseStates.kt Adds NativeAuthState and updates V1 BaseState to extend it (shared correlation metadata).
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​NativeAuthBaseStateV2.kt Removes legacy continuation-token placeholder from V2 base state and updates parcel write order/documentation.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​CodeRequiredStateV2.kt Updates V2 state constructor/parcel ctor to match new V2 base-state contract.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​PasswordRequiredStateV2.kt Same: removes raw-token plumbing from V2 state construction/parceling.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​NewPasswordRequiredStateV2.kt Same: aligns with new V2 base-state contract.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​AttributesRequiredStateV2.kt Same: aligns with new V2 base-state contract.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​AttributesInvalidStateV2.kt Same: aligns with new V2 base-state contract.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​MFARequiredStateV2.kt Same: removes raw-token placeholder and updates parcel constructor ordering.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​MFAVerificationRequiredStateV2.kt Same: aligns state parceling with new V2 base write order.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​ResetPasswordMethodRequiredStateV2.kt Same: removes raw-token placeholder from V2 state plumbing.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​SignInAfterResetPasswordStateV2.kt Same: removes raw-token placeholder and updates parcel ctor ordering.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​SignInAfterSignUpStateV2.kt Same: removes raw-token placeholder and updates parcel ctor ordering.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​StrongAuthRegistrationRequiredStateV2.kt Same: removes raw-token placeholder and updates parcel ctor ordering.
msal/​src/​main/​java/​com/​microsoft/​identity/​nativeauth/​statemachine/​states/​StrongAuthVerificationRequiredStateV2.kt Same: removes raw-token placeholder and updates parcel ctor ordering.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2StatesTest.kt Adds/updates regression tests for V2 inheritance and parcel prefix/order; expands V2 parcel round-trip checks.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2ResultsTest.kt Updates result tests to construct V2 next-states without legacy continuation token.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2SignInTest.kt Removes V2 continuation-token assertions and updates Parcel round-trip helper to marshall/unmarshall.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2SignUpTest.kt Removes V2 continuation-token assertions consistent with refactor.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2InterfaceKotlinTest.kt Updates invalid-state test construction and adds Bundle restore + config reinit coverage.
msal/​src/​test/​java/​com/​microsoft/​identity/​nativeauth/​v2/​NativeAuthV2InterfaceJavaTest.java Updates Java API tests to construct V2 states without legacy continuation token.

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

Comment thread msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2StatesTest.kt Outdated
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

❌ Work item link check failed. Description contains AB#3739969 but the Bot could not link it to an Azure Boards work item.

Click here to learn more.

Update assertion for continuation state string to check for redacted content and ensure scope is not included.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

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.

Copilot review overview

🟢 Approval recommended

The inheritance and parcel changes are internally consistent, preserve V1 behavior, and have comprehensive regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Leave V1 BaseState unchanged and let NativeAuthBaseStateV2 own its correlation metadata without a shared superclass. Add a hierarchy regression assertion.

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

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

✅ Work item link check complete. Description contains link AB#3739969 to an Azure Boards work item.

@spetrescu84
Silviu Petrescu (spetrescu84) merged commit 4477bed into dev Oct 8, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:none No changelog entry or version increment is required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants