From 92ece8fb8d0b834151380c956d0bb6e6467284c5 Mon Sep 17 00:00:00 2001 From: Disha Janardhan Date: Mon, 12 Oct 2026 11:36:02 -0700 Subject: [PATCH 1/3] Port Native Auth V2 entry scopes and claims to Android Fixes AB#3784690 Thread typed entry claims and scopes through public APIs and adapters, snapshot callback inputs, and retain null-versus-empty continuation semantics. Include JS8898 empty/short OTP service-validation parity. Token retains scope and omits claims; V1 is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0bcd671b-73fa-4ee6-bcd6-65d7eea4d753 --- changelog | 1 + common | 2 +- .../internal/CommandParametersAdapter.java | 30 ++++- .../NativeAuthPublicClientApplication.kt | 24 +++- .../NativeAuthResetPasswordParameters.kt | 10 +- .../NativeAuthSignInContinuationParameters.kt | 4 +- .../parameters/NativeAuthSignUpParameters.kt | 7 ++ .../states/CodeRequiredStateV2.kt | 8 -- .../states/MFAVerificationRequiredStateV2.kt | 8 -- .../v2/NativeAuthV2InterfaceKotlinTest.kt | 117 +++++++++++++++++- .../nativeauth/v2/NativeAuthV2SignInTest.kt | 39 ++++-- .../nativeauth/v2/NativeAuthV2SignUpTest.kt | 14 +++ 12 files changed, 225 insertions(+), 39 deletions(-) diff --git a/changelog b/changelog index df4044d2a0..e6e339cccb 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-andr vNext ---------- - [MAJOR] Native Auth V2 errors now use NativeAuthErrorV2. Replace operation-specific V2 error type checks with its classifiers; rejected sign-in passwords use isInvalidCredentials, not isInvalidPassword. V1 is unchanged (AB#3784695). +- [MINOR] Native Auth V2 sign-in, sign-up and password-reset entries accept scopes and claims. Scope is also sent at token exchange; claims are sent only at entry. Null continuation scopes retain entry scopes, while explicit empty scopes request default OIDC scopes (AB#3784690). Version 8.5.0 ---------- diff --git a/common b/common index 1505acff7e..52e5eb6b3c 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 1505acff7e479a67a0cd47cfa94ad079dc158918 +Subproject commit 52e5eb6b3ca1cd5690ce97f7b3f7461b2fd4ea57 diff --git a/msal/src/main/java/com/microsoft/identity/client/internal/CommandParametersAdapter.java b/msal/src/main/java/com/microsoft/identity/client/internal/CommandParametersAdapter.java index 8a96decec5..303ea7aedb 100644 --- a/msal/src/main/java/com/microsoft/identity/client/internal/CommandParametersAdapter.java +++ b/msal/src/main/java/com/microsoft/identity/client/internal/CommandParametersAdapter.java @@ -1077,9 +1077,7 @@ public static ResetPasswordSubmitNewPasswordCommandParameters createResetPasswor /** * Creates command parameter for [NativeAuthV2ResetPasswordStartCommand] of Native Auth. * - * No scopes are supplied at the start of a reset-password flow. Matching MSAL iOS/macOS, the - * scopes for the resulting access token are supplied at the sign-in-after-reset-password step - * instead, since no token is issued until then. + * Scopes and claims are supplied at V2 authorize-challenge entry. * * @param configuration PCA configuration * @param tokenCache token cache for storing results @@ -1090,6 +1088,16 @@ public static ResetPasswordV2StartCommandParameters createResetPasswordV2StartCo @NonNull final NativeAuthPublicClientApplicationConfiguration configuration, @NonNull final OAuth2TokenCache tokenCache, @NonNull final String username) throws ClientException { + return createResetPasswordV2StartCommandParameters(configuration, tokenCache, username, null, null); + } + + /** Creates V2 reset entry parameters with optional scopes and claims. */ + public static ResetPasswordV2StartCommandParameters createResetPasswordV2StartCommandParameters( + @NonNull final NativeAuthPublicClientApplicationConfiguration configuration, + @NonNull final OAuth2TokenCache tokenCache, + @NonNull final String username, + @Nullable final List scopes, + @Nullable final ClaimsRequest claimsRequest) throws ClientException { final NativeAuthCIAMAuthority authority = ((NativeAuthCIAMAuthority) configuration.getDefaultAuthority()); @@ -1100,6 +1108,8 @@ public static ResetPasswordV2StartCommandParameters createResetPasswordV2StartCo final ResetPasswordV2StartCommandParameters commandParameters = ResetPasswordV2StartCommandParameters.builder() + .scopes(scopes == null ? null : new ArrayList<>(scopes)) + .claimsRequestJson(ClaimsRequest.getJsonStringFromClaimsRequest(claimsRequest)) .platformComponents(AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext())) .applicationName(configuration.getAppContext().getPackageName()) .applicationVersion(getPackageVersion(configuration.getAppContext())) @@ -1141,6 +1151,18 @@ public static SignUpV2StartCommandParameters createSignUpV2StartCommandParameter @NonNull final String username, @Nullable final char[] password, @Nullable final Map attributes) throws ClientException { + return createSignUpV2StartCommandParameters(configuration, tokenCache, username, password, attributes, null, null); + } + + /** Creates V2 sign-up entry parameters with optional scopes and claims. */ + public static SignUpV2StartCommandParameters createSignUpV2StartCommandParameters( + @NonNull final NativeAuthPublicClientApplicationConfiguration configuration, + @NonNull final OAuth2TokenCache tokenCache, + @NonNull final String username, + @Nullable final char[] password, + @Nullable final Map attributes, + @Nullable final List scopes, + @Nullable final ClaimsRequest claimsRequest) throws ClientException { final NativeAuthCIAMAuthority authority = ((NativeAuthCIAMAuthority) configuration.getDefaultAuthority()); @@ -1151,6 +1173,8 @@ public static SignUpV2StartCommandParameters createSignUpV2StartCommandParameter final SignUpV2StartCommandParameters commandParameters = SignUpV2StartCommandParameters.builder() + .scopes(scopes == null ? null : new ArrayList<>(scopes)) + .claimsRequestJson(ClaimsRequest.getJsonStringFromClaimsRequest(claimsRequest)) .platformComponents(AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext())) .applicationName(configuration.getAppContext().getPackageName()) .applicationVersion(getPackageVersion(configuration.getAppContext())) diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplication.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplication.kt index 09d35189a4..98007e472b 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplication.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplication.kt @@ -810,7 +810,9 @@ class NativeAuthPublicClientApplication( val parametersSnapshot = NativeAuthSignInParameters(parameters.username).also { it.password = parameters.password?.copyOf() it.scopes = parameters.scopes?.toList() - it.claimsRequest = parameters.claimsRequest + it.claimsRequest = parameters.claimsRequest?.let { claims -> + ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims)) + } } pcaScope.launchOwningPasswordSnapshot(parametersSnapshot.password) { try { @@ -854,7 +856,9 @@ class NativeAuthPublicClientApplication( nativeAuthConfig.oAuth2TokenCache, parameters.username, passwordCopy, - parameters.attributes?.toMap() + parameters.attributes?.toMap(), + parameters.scopes?.toList(), + parameters.claimsRequest ) correlationId = cmdParams.correlationId ?: correlationId @@ -1016,6 +1020,10 @@ class NativeAuthPublicClientApplication( ) val parametersSnapshot = NativeAuthSignUpParameters(parameters.username).also { it.password = parameters.password?.copyOf() + it.scopes = parameters.scopes?.toList() + it.claimsRequest = parameters.claimsRequest?.let { claims -> + ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims)) + } it.attributes = parameters.attributes?.let { attributes -> UserAttributes(attributes.toMap()) } @@ -1056,7 +1064,9 @@ class NativeAuthPublicClientApplication( val cmdParams = CommandParametersAdapter.createResetPasswordV2StartCommandParameters( nativeAuthConfig, nativeAuthConfig.oAuth2TokenCache, - parameters.username + parameters.username, + parameters.scopes?.toList(), + parameters.claimsRequest ) correlationId = cmdParams.correlationId ?: correlationId @@ -1201,9 +1211,15 @@ class NativeAuthPublicClientApplication( correlationId = null, methodName = "${TAG}.resetPasswordV2(parameters: NativeAuthResetPasswordParameters, callback: NativeAuthV2Callback)" ) + val parametersSnapshot = NativeAuthResetPasswordParameters(parameters.username).also { + it.scopes = parameters.scopes?.toList() + it.claimsRequest = parameters.claimsRequest?.let { claims -> + ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims)) + } + } pcaScope.launch { try { - callback.onResult(resetPasswordV2(parameters)) + callback.onResult(resetPasswordV2(parametersSnapshot)) } catch (e: MsalException) { Logger.error(TAG, "Exception thrown in resetPasswordV2", e) callback.onError(e) diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthResetPasswordParameters.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthResetPasswordParameters.kt index f01ad7d31c..04b9ae333e 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthResetPasswordParameters.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthResetPasswordParameters.kt @@ -23,6 +23,8 @@ package com.microsoft.identity.nativeauth.parameters +import com.microsoft.identity.client.claims.ClaimsRequest + /** * Encapsulates the parameters passed to the resetPassword methods of NativeAuthPublicClientApplication. * @@ -30,4 +32,10 @@ package com.microsoft.identity.nativeauth.parameters */ class NativeAuthResetPasswordParameters( val username: String -) \ No newline at end of file +) { + /** V2-only requested scopes. Null or empty uses default OIDC scopes; ignored by V1. */ + var scopes: List? = null + + /** V2-only claims sent at authorize-challenge entry; ignored by V1. */ + var claimsRequest: ClaimsRequest? = null +} \ No newline at end of file diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignInContinuationParameters.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignInContinuationParameters.kt index 0077d85b55..85b33f079e 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignInContinuationParameters.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignInContinuationParameters.kt @@ -33,11 +33,13 @@ class NativeAuthSignInContinuationParameters { /** * Permissions you want included in the access token received. * Not all scopes are guaranteed to be included in the access token returned. + * For V2, null retains entry scopes; an explicit empty list requests only default OIDC scopes. */ var scopes: List? = null /** - * The claims parameter that needs to be sent to the service. + * Claims sent to the service in V1. In V2, claims are retained locally for token/cache + * semantics, but the token exchange omits claims; supply service claims at flow entry. */ var claimsRequest: ClaimsRequest? = null } \ No newline at end of file diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignUpParameters.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignUpParameters.kt index ac07dbf134..21481980d7 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignUpParameters.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/parameters/NativeAuthSignUpParameters.kt @@ -24,6 +24,7 @@ package com.microsoft.identity.nativeauth.parameters import com.microsoft.identity.nativeauth.UserAttributes +import com.microsoft.identity.client.claims.ClaimsRequest /** * Encapsulates the parameters passed to the signUp methods of NativeAuthPublicClientApplication @@ -47,4 +48,10 @@ class NativeAuthSignUpParameters( * Supply them through the dedicated [username] and [password] properties instead. */ var attributes: UserAttributes? = null + + /** V2-only requested scopes. Null or empty uses default OIDC scopes; ignored by V1. */ + var scopes: List? = null + + /** V2-only claims sent at authorize-challenge entry; ignored by V1. */ + var claimsRequest: ClaimsRequest? = null } \ No newline at end of file diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/CodeRequiredStateV2.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/CodeRequiredStateV2.kt index 53f3e43a61..b9534fb5c7 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/CodeRequiredStateV2.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/CodeRequiredStateV2.kt @@ -116,14 +116,6 @@ class CodeRequiredStateV2 internal constructor( methodName = "${TAG}.submitCode(code: String)" ) val state = continuationState ?: return invalidState() - if (code.isEmpty()) { - return NativeAuthErrorV2( - errorType = ErrorTypes.INVALID_CODE, - errorMessage = "Code cannot be empty.", - correlationId = correlationId, - scenario = scenario - ) - } if (scenario == NativeAuthFlowScenarioV2.UNKNOWN) { return invalidState() } diff --git a/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/MFAVerificationRequiredStateV2.kt b/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/MFAVerificationRequiredStateV2.kt index beefaa4cb9..cd2ea90620 100644 --- a/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/MFAVerificationRequiredStateV2.kt +++ b/msal/src/main/java/com/microsoft/identity/nativeauth/statemachine/states/MFAVerificationRequiredStateV2.kt @@ -127,14 +127,6 @@ class MFAVerificationRequiredStateV2 internal constructor( methodName = "${TAG}.submitChallenge(challenge: String)" ) val state = continuationState ?: return invalidState() - if (challenge.isEmpty()) { - return NativeAuthErrorV2( - errorType = ErrorTypes.INVALID_CODE, - errorMessage = "Challenge cannot be empty.", - correlationId = correlationId, - scenario = scenario - ) - } return withContext(Dispatchers.IO) { try { val parameters = CommandParametersAdapter.createNativeAuthV2SubmitMFAChallengeCommandParameters( diff --git a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2InterfaceKotlinTest.kt b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2InterfaceKotlinTest.kt index 66b220fa51..4aa4142345 100644 --- a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2InterfaceKotlinTest.kt +++ b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2InterfaceKotlinTest.kt @@ -127,6 +127,106 @@ class NativeAuthV2InterfaceKotlinTest : PublicClientApplicationAbstractTest() { private lateinit var application: INativeAuthPublicClientApplication private val username = "user@email.com" + @Test + fun allV2EntriesPropagateNullableScopesAndTypedClaimsThroughAdapters() = runTest { + val claims = com.microsoft.identity.client.claims.ClaimsRequest().also { + it.requestClaimInIdToken("auth_time", null) + } + val expectedClaims = com.microsoft.identity.client.claims.ClaimsRequest.getJsonStringFromClaimsRequest(claims) + listOf?>(null, emptyList(), listOf("User.Read")).forEach { scopes -> + var captured: com.microsoft.identity.common.java.nativeauth.commands.parameters.BaseSignInTokenCommandParameters? = null + fun capture(command: BaseCommand<*>) { + captured = command.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.BaseSignInTokenCommandParameters + } + fun assertCaptured() { + assertTrue(captured != null) + assertEquals(scopes, captured?.scopes) + assertEquals(expectedClaims, captured?.claimsRequestJson) + captured = null + } + val result = INativeAuthCommandResult.APIError("test_stop", "test stop", correlationId = correlationId) + enqueueResult(result, com.microsoft.identity.common.nativeauth.internal.commands.NativeAuthV2SignInStartCommand::class, ::capture) + application.signInV2(NativeAuthSignInParameters(username).also { + it.scopes = scopes + it.claimsRequest = claims + }) + assertCaptured() + enqueueResult(result, NativeAuthV2SignUpStartCommand::class, ::capture) + application.signUpV2(NativeAuthSignUpParameters(username).also { + it.scopes = scopes + it.claimsRequest = claims + }) + assertCaptured() + enqueueResult(result, NativeAuthV2ResetPasswordStartCommand::class, ::capture) + application.resetPasswordV2(NativeAuthResetPasswordParameters(username).also { + it.scopes = scopes + it.claimsRequest = claims + }) + assertCaptured() + } + } + + @Test + fun sharedEntryScopesAndClaimsDoNotChangeV1CommandInputsOrErrors() = runTest { + val claims = com.microsoft.identity.client.claims.ClaimsRequest().also { it.requestClaimInIdToken("auth_time", null) } + var signUpInputs: com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpStartCommandParameters? = null + var resetInputs: com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordStartCommandParameters? = null + val result = INativeAuthCommandResult.APIError("test_stop", "test stop", correlationId = correlationId) + enqueueResult(result, com.microsoft.identity.common.nativeauth.internal.commands.SignUpStartCommand::class) { + signUpInputs = it.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpStartCommandParameters + } + enqueueResult(result, com.microsoft.identity.common.nativeauth.internal.commands.ResetPasswordStartCommand::class) { + resetInputs = it.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordStartCommandParameters + } + val signUp = application.signUp(NativeAuthSignUpParameters(username).also { + it.scopes = listOf("V2.Only") + it.claimsRequest = claims + }) + val reset = application.resetPassword(NativeAuthResetPasswordParameters(username).also { + it.scopes = listOf("V2.Only") + it.claimsRequest = claims + }) + assertTrue(signUp is com.microsoft.identity.nativeauth.statemachine.errors.SignUpError) + assertTrue(reset is com.microsoft.identity.nativeauth.statemachine.errors.ResetPasswordError) + assertEquals(username, signUpInputs?.username) + assertEquals(null, signUpInputs?.userAttributes) + assertEquals(null, signUpInputs?.password) + assertEquals(username, resetInputs?.username) + assertEquals("test_stop", (reset as com.microsoft.identity.nativeauth.statemachine.errors.ResetPasswordError).error) + } + + @Test + fun resetPasswordCallbackSnapshotsScopesAndMutableClaimsBeforeLaunch() = runTest { + val scopes = mutableListOf("User.Read") + val claims = com.microsoft.identity.client.claims.ClaimsRequest().also { + it.requestClaimInIdToken("auth_time", null) + } + val expectedClaims = com.microsoft.identity.client.claims.ClaimsRequest.getJsonStringFromClaimsRequest(claims) + var captured: com.microsoft.identity.common.java.nativeauth.commands.parameters.BaseSignInTokenCommandParameters? = null + enqueueResult( + INativeAuthCommandResult.APIError("test_stop", "test stop", correlationId = correlationId), + NativeAuthV2ResetPasswordStartCommand::class + ) { command -> + captured = command.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.BaseSignInTokenCommandParameters + } + val parameters = NativeAuthResetPasswordParameters(username).also { + it.scopes = scopes + it.claimsRequest = claims + } + val future = ResultFuture() + application.resetPasswordV2(parameters, object : NativeAuthPublicClientApplication.NativeAuthV2Callback { + override fun onResult(result: NativeAuthResultV2) = future.setResult(result) + override fun onError(exception: BaseException) = future.setException(exception) + }) + scopes.clear() + claims.requestClaimInIdToken("changed", null) + parameters.claimsRequest = null + assertTrue(future.get(30, TimeUnit.SECONDS) is NativeAuthErrorV2) + assertTrue(captured != null) + assertEquals(listOf("User.Read"), captured?.scopes) + assertEquals(expectedClaims, captured?.claimsRequestJson) + } + override fun getConfigFilePath() = "src/test/res/raw/native_auth_native_only_test_config.json" @Before @@ -573,12 +673,21 @@ class NativeAuthV2InterfaceKotlinTest : PublicClientApplicationAbstractTest() { } @Test - fun submitCodeRejectsEmptyInputWithRetryableInvalidCodeError() = runTest { + fun submitCodeSendsEmptyAndShortInputToServiceAndRemainsRetryable() = runTest { val state = codeRequiredState() - val error = state.submitCode("") as NativeAuthErrorV2 - - assertTrue(error.isInvalidCode()) + listOf("", "1").forEach { code -> + var submittedCode: String? = null + enqueueResult( + NativeAuthV2CommandResult.IncorrectCode(correlationId, "invalidGrant", "invalid", "invalidOneTimeCode"), + NativeAuthV2ResetPasswordSubmitCodeCommand::class + ) { command -> + submittedCode = (command.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.NativeAuthV2SubmitCodeCommandParameters).code + } + val error = state.submitCode(code) as NativeAuthErrorV2 + assertTrue(error.isInvalidCode()) + assertEquals(code, submittedCode) + } } @Test diff --git a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignInTest.kt b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignInTest.kt index 5c4efb04d1..a53a233b50 100644 --- a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignInTest.kt +++ b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignInTest.kt @@ -374,17 +374,25 @@ class NativeAuthV2SignInTest : PublicClientApplicationAbstractTest() { @Test fun signInV2CallbackSnapshotsThePasswordSynchronouslyBeforeLaunch() = runTest { var capturedPassword: CharArray? = null + var capturedScopes: List? = null + var capturedClaims: String? = null enqueueResult( NativeAuthV2CommandResult.PasswordRequired(correlationId, createContinuationState()), NativeAuthV2SignInStartCommand::class ) { command -> - capturedPassword = (command.parameters as SignInV2StartCommandParameters).password?.copyOf() + val commandParameters = command.parameters as SignInV2StartCommandParameters + capturedPassword = commandParameters.password?.copyOf() + capturedScopes = commandParameters.scopes + capturedClaims = commandParameters.claimsRequestJson } val callerPassword = "Password123!".toCharArray() val future = ResultFuture() + val scopes = mutableListOf("User.Read") + val claims = com.microsoft.identity.client.claims.ClaimsRequest().also { it.requestClaimInIdToken("auth_time", null) } + val expectedClaims = com.microsoft.identity.client.claims.ClaimsRequest.getJsonStringFromClaimsRequest(claims) application.signInV2( - signInParameters(password = callerPassword), + signInParameters(password = callerPassword, scopes = scopes).also { it.claimsRequest = claims }, object : NativeAuthPublicClientApplication.NativeAuthV2Callback { override fun onResult(result: NativeAuthResultV2) = future.setResult(result) override fun onError(exception: BaseException) = future.setException(exception) @@ -395,10 +403,14 @@ class NativeAuthV2SignInTest : PublicClientApplicationAbstractTest() { // the coroutine body, as opposed to synchronously before launch), this mutation could race // with -- and change -- what actually gets submitted to Common. callerPassword.fill('X') + scopes.clear() + claims.requestClaimInIdToken("changed", null) future.get(10, TimeUnit.SECONDS) assertEquals("Password123!", String(capturedPassword!!)) + assertEquals(listOf("User.Read"), capturedScopes) + assertEquals(expectedClaims, capturedClaims) } @Test @@ -625,7 +637,7 @@ class NativeAuthV2SignInTest : PublicClientApplicationAbstractTest() { assertTrue(result is NativeAuthErrorV2) result as NativeAuthErrorV2 - assertTrue(result.isInvalidInput()) + assertTrue(result.isInvalidCredentials()) assertFalse(result.isInvalidPassword()) assertEquals(errorCodes, result.errorCodes) } @@ -636,7 +648,7 @@ class NativeAuthV2SignInTest : PublicClientApplicationAbstractTest() { val result = state.submitPassword(CharArray(0)) as NativeAuthErrorV2 - assertTrue(result.isInvalidCredentials()) + assertTrue(result.isInvalidInput()) assertFalse(result.isInvalidPassword()) } @@ -977,13 +989,22 @@ class NativeAuthV2SignInTest : PublicClientApplicationAbstractTest() { } @Test - fun submitChallengeRejectsAnEmptyCodeWithoutIssuingACommand() = runTest { + fun submitChallengeSendsEmptyAndShortCodesToServiceAndRemainsRetryable() = runTest { val verificationState = mfaVerificationState(mfaRequiredState()) - val result = verificationState.submitChallenge("") as NativeAuthErrorV2 - - assertTrue(result.isInvalidChallenge()) - assertEquals(ErrorTypes.INVALID_CODE, result.errorType) + listOf("", "1").forEach { code -> + var submittedCode: String? = null + enqueueResult( + NativeAuthV2CommandResult.IncorrectCode(correlationId, "invalidGrant", "invalid", "invalidOneTimeCode"), + NativeAuthV2SubmitMFAChallengeCommand::class + ) { command -> + submittedCode = (command.parameters as com.microsoft.identity.common.java.nativeauth.commands.parameters.NativeAuthV2SubmitMFAChallengeCommandParameters).code + } + val result = verificationState.submitChallenge(code) as NativeAuthErrorV2 + assertTrue(result.isInvalidChallenge()) + assertTrue(result.isInvalidCode()) + assertEquals(code, submittedCode) + } } @Test diff --git a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignUpTest.kt b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignUpTest.kt index 5ec4471f14..16eeb5c234 100644 --- a/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignUpTest.kt +++ b/msal/src/test/java/com/microsoft/identity/nativeauth/v2/NativeAuthV2SignUpTest.kt @@ -449,6 +449,8 @@ class NativeAuthV2SignUpTest : PublicClientApplicationAbstractTest() { var capturedUsername: String? = null var capturedPassword: CharArray? = null var capturedAttributes: Map? = null + var capturedScopes: List? = null + var capturedClaims: String? = null enqueueResult( NativeAuthV2CommandResult.PasswordRequired(correlationId, createContinuationState()), NativeAuthV2SignUpStartCommand::class @@ -457,6 +459,8 @@ class NativeAuthV2SignUpTest : PublicClientApplicationAbstractTest() { capturedUsername = commandParameters.username capturedPassword = commandParameters.password?.copyOf() capturedAttributes = commandParameters.attributes?.toMap() + capturedScopes = commandParameters.scopes + capturedClaims = commandParameters.claimsRequestJson } val callerPassword = "Password123!".toCharArray() @@ -466,6 +470,11 @@ class NativeAuthV2SignUpTest : PublicClientApplicationAbstractTest() { password = callerPassword, attributes = attributesBuilder.build() ) + val scopes = mutableListOf("User.Read") + val claims = com.microsoft.identity.client.claims.ClaimsRequest().also { it.requestClaimInIdToken("auth_time", null) } + val expectedClaims = com.microsoft.identity.client.claims.ClaimsRequest.getJsonStringFromClaimsRequest(claims) + parameters.scopes = scopes + parameters.claimsRequest = claims val future = ResultFuture() application.signUpV2( parameters, @@ -478,12 +487,17 @@ class NativeAuthV2SignUpTest : PublicClientApplicationAbstractTest() { attributesBuilder.city("Seattle") parameters.password = null parameters.attributes = null + scopes.clear() + claims.requestClaimInIdToken("changed", null) + parameters.claimsRequest = null future.get(10, TimeUnit.SECONDS) assertEquals(username, capturedUsername) assertEquals("Password123!", String(capturedPassword!!)) assertEquals(mapOf("city" to "Redmond"), capturedAttributes) + assertEquals(listOf("User.Read"), capturedScopes) + assertEquals(expectedClaims, capturedClaims) } @Test From 12a5e97e8bf08a05a2927e1780d6c8db3579974f Mon Sep 17 00:00:00 2001 From: Disha Janardhan Date: Mon, 12 Oct 2026 12:07:07 -0700 Subject: [PATCH 2/3] Correct unified-error password assertions and pair repaired Common Fixes AB#3784695 Rejected credentials are invalid credentials; empty password input is invalid input. Use independently validated Common diagnostic-forwarding repair. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0bcd671b-73fa-4ee6-bcd6-65d7eea4d753 (cherry picked from commit 7ac5b2d593ed270d67c910ad2af87aeaf01a2166) --- common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common b/common index 52e5eb6b3c..5325fa9f95 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 52e5eb6b3ca1cd5690ce97f7b3f7461b2fd4ea57 +Subproject commit 5325fa9f9579e6f58e348c16f3dd97e0c542708a From f92d6c06ed448f29d97b93e24ef98c78b1b4dfb3 Mon Sep 17 00:00:00 2001 From: Disha Janardhan Date: Mon, 12 Oct 2026 12:16:54 -0700 Subject: [PATCH 3/3] Pair validated canonical OIDC scope Common update Fixes AB#3784690 Use the Common scope-canonicalization fix validated with MSAL/Common focused suites; retain carried unified-error repair and existing scopes/claims wire policy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0bcd671b-73fa-4ee6-bcd6-65d7eea4d753 --- common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common b/common index 5325fa9f95..41f9c0f74a 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 5325fa9f9579e6f58e348c16f3dd97e0c542708a +Subproject commit 41f9c0f74a636b1ae2f62abcb3ee6a94906f1d86