Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
2 changes: 1 addition & 1 deletion common
Submodule common updated 17 files
+1 −0 changelog.txt
+50 −375 common/src/main/java/com/microsoft/identity/common/internal/broker/AuthUxJavaScriptInterface.kt
+30 −10 ...rc/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/v2/NativeAuthV2FlowController.kt
+144 −102 common/src/test/java/com/microsoft/identity/common/internal/broker/AuthUxJavaScriptInterfaceTest.kt
+57 −9 ...java/com/microsoft/identity/common/nativeauth/internal/controllers/v2/NativeAuthV2SSPRFlowControllerTest.kt
+5 −3 ...va/com/microsoft/identity/common/nativeauth/internal/controllers/v2/NativeAuthV2SignInFlowControllerTest.kt
+55 −2 ...va/com/microsoft/identity/common/nativeauth/internal/controllers/v2/NativeAuthV2SignUpFlowControllerTest.kt
+2 −1 ...ain/com/microsoft/identity/common/java/nativeauth/commands/parameters/BaseSignInTokenCommandParameters.java
+2 −2 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthV2OAuth2Strategy.kt
+5 −1 ...on4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/interactors/NativeAuthV2Interactor.kt
+35 −5 .../main/com/microsoft/identity/common/java/nativeauth/providers/requests/v2/AuthorizeChallengeStartRequest.kt
+2 −1 ...4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/requests/v2/NativeAuthV2TokenRequest.kt
+0 −1 ...j/src/main/com/microsoft/identity/common/java/nativeauth/providers/requests/v2/NativeAuthV2VerifyRequest.kt
+20 −1 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/v2/NativeAuthV2RequestProvider.kt
+15 −8 .../src/test/com/microsoft/identity/common/java/nativeauth/providers/interactors/NativeAuthV2InteractorTest.kt
+46 −0 ...com/microsoft/identity/common/java/nativeauth/providers/requests/v2/NativeAuthV2RequestSerializationTest.kt
+5 −2 ...rc/test/com/microsoft/identity/common/java/nativeauth/providers/requests/v2/NativeAuthV2TokenRequestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> scopes,
@Nullable final ClaimsRequest claimsRequest) throws ClientException {

final NativeAuthCIAMAuthority authority = ((NativeAuthCIAMAuthority) configuration.getDefaultAuthority());

Expand All @@ -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()))
Expand Down Expand Up @@ -1141,6 +1151,18 @@ public static SignUpV2StartCommandParameters createSignUpV2StartCommandParameter
@NonNull final String username,
@Nullable final char[] password,
@Nullable final Map<String, String> 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<String, String> attributes,
@Nullable final List<String> scopes,
@Nullable final ClaimsRequest claimsRequest) throws ClientException {

final NativeAuthCIAMAuthority authority = ((NativeAuthCIAMAuthority) configuration.getDefaultAuthority());

Expand All @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,32 @@ class NativeAuthPublicClientApplication(
correlationId = null,
methodName = "${TAG}.signInV2(parameters: NativeAuthSignInParameters, callback: NativeAuthV2Callback)"
)
val parametersSnapshot = NativeAuthSignInParameters(parameters.username).also {
it.password = parameters.password?.copyOf()
it.scopes = parameters.scopes?.toList()
it.claimsRequest = parameters.claimsRequest
val parametersSnapshot = NativeAuthSignInParameters(parameters.username)
val snapshotError = try {
parametersSnapshot.password = parameters.password?.copyOf()
parametersSnapshot.scopes = parameters.scopes?.toList()
parametersSnapshot.claimsRequest = parameters.claimsRequest?.let { claims ->
ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims))
}
null
} catch (e: CancellationException) {
StringUtil.overwriteWithNull(parametersSnapshot.password)
throw e
} catch (e: Exception) {
StringUtil.overwriteWithNull(parametersSnapshot.password)
val correlationId = DiagnosticContext.INSTANCE.threadCorrelationId ?: "UNSET"
Logger.error(TAG, correlationId, "Exception thrown in signInV2", e)
NativeAuthErrorV2(
errorType = ErrorTypes.CLIENT_EXCEPTION,
errorMessage = "MSAL client exception occurred in signInV2.",
correlationId = correlationId,
scenario = NativeAuthFlowScenarioV2.SIGN_IN,
exception = e
)
}
pcaScope.launchOwningPasswordSnapshot(parametersSnapshot.password) {
try {
callback.onResult(signInV2(parametersSnapshot))
callback.onResult(snapshotError ?: signInV2(parametersSnapshot))
} catch (e: MsalException) {
Logger.error(TAG, "Exception thrown in signInV2", e)
callback.onError(e)
Expand Down Expand Up @@ -865,7 +883,9 @@ class NativeAuthPublicClientApplication(
nativeAuthConfig.oAuth2TokenCache,
parameters.username,
passwordCopy,
parameters.attributes?.toMap()
parameters.attributes?.toMap(),
parameters.scopes?.toList(),
parameters.claimsRequest
)
correlationId = cmdParams.correlationId ?: correlationId

Expand Down Expand Up @@ -1034,15 +1054,35 @@ class NativeAuthPublicClientApplication(
correlationId = null,
methodName = "${TAG}.signUpV2(parameters: NativeAuthSignUpParameters, callback: NativeAuthV2Callback)"
)
val parametersSnapshot = NativeAuthSignUpParameters(parameters.username).also {
it.password = parameters.password?.copyOf()
it.attributes = parameters.attributes?.let { attributes ->
val parametersSnapshot = NativeAuthSignUpParameters(parameters.username)
val snapshotError = try {
parametersSnapshot.password = parameters.password?.copyOf()
parametersSnapshot.scopes = parameters.scopes?.toList()
parametersSnapshot.claimsRequest = parameters.claimsRequest?.let { claims ->
ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims))
}
parametersSnapshot.attributes = parameters.attributes?.let { attributes ->
UserAttributes(attributes.toMap())
}
null
} catch (e: CancellationException) {
StringUtil.overwriteWithNull(parametersSnapshot.password)
throw e
} catch (e: Exception) {
StringUtil.overwriteWithNull(parametersSnapshot.password)
val correlationId = DiagnosticContext.INSTANCE.threadCorrelationId ?: "UNSET"
Logger.error(TAG, correlationId, "Exception thrown in signUpV2", e)
NativeAuthErrorV2(
errorType = ErrorTypes.CLIENT_EXCEPTION,
errorMessage = "MSAL client exception occurred in signUpV2.",
correlationId = correlationId,
scenario = NativeAuthFlowScenarioV2.SIGN_UP,
exception = e
)
}
pcaScope.launchOwningPasswordSnapshot(parametersSnapshot.password) {
try {
callback.onResult(signUpV2(parametersSnapshot))
callback.onResult(snapshotError ?: signUpV2(parametersSnapshot))
} catch (e: MsalException) {
Logger.error(TAG, "Exception thrown in signUpV2", e)
callback.onError(e)
Expand Down Expand Up @@ -1076,7 +1116,9 @@ class NativeAuthPublicClientApplication(
val cmdParams = CommandParametersAdapter.createResetPasswordV2StartCommandParameters(
nativeAuthConfig,
nativeAuthConfig.oAuth2TokenCache,
parameters.username
parameters.username,
parameters.scopes?.toList(),
parameters.claimsRequest
)
correlationId = cmdParams.correlationId ?: correlationId

Expand Down Expand Up @@ -1230,9 +1272,29 @@ class NativeAuthPublicClientApplication(
correlationId = null,
methodName = "${TAG}.resetPasswordV2(parameters: NativeAuthResetPasswordParameters, callback: NativeAuthV2Callback)"
)
val parametersSnapshot = NativeAuthResetPasswordParameters(parameters.username)
val snapshotError = try {
parametersSnapshot.scopes = parameters.scopes?.toList()
parametersSnapshot.claimsRequest = parameters.claimsRequest?.let { claims ->
ClaimsRequest.getClaimsRequestFromJsonString(ClaimsRequest.getJsonStringFromClaimsRequest(claims))
}
null
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
val correlationId = DiagnosticContext.INSTANCE.threadCorrelationId ?: "UNSET"
Logger.error(TAG, correlationId, "Exception thrown in resetPasswordV2", e)
NativeAuthErrorV2(
errorType = ErrorTypes.CLIENT_EXCEPTION,
errorMessage = "MSAL client exception occurred in resetPasswordV2.",
correlationId = correlationId,
scenario = NativeAuthFlowScenarioV2.RESET_PASSWORD,
exception = e
)
}
pcaScope.launch {
try {
callback.onResult(resetPasswordV2(parameters))
callback.onResult(snapshotError ?: resetPasswordV2(parametersSnapshot))
} catch (e: MsalException) {
Logger.error(TAG, "Exception thrown in resetPasswordV2", e)
callback.onError(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@

package com.microsoft.identity.nativeauth.parameters

import com.microsoft.identity.client.claims.ClaimsRequest

/**
* Encapsulates the parameters passed to the resetPassword methods of NativeAuthPublicClientApplication.
*
* @param username username of the account whose password will be reset.
*/
class NativeAuthResetPasswordParameters(
val username: String
)
) {
/** V2-only requested scopes. Null or empty uses default OIDC scopes; ignored by V1. */
var scopes: List<String>? = null

/** V2-only claims sent at authorize-challenge entry; ignored by V1. */
var claimsRequest: ClaimsRequest? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? = 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>? = null

/** V2-only claims sent at authorize-challenge entry; ignored by V1. */
var claimsRequest: ClaimsRequest? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading
Loading