Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the signature of signup/signin methods #2010

Merged
merged 11 commits into from
Jan 22, 2024
2 changes: 1 addition & 1 deletion common
Submodule common updated 19 files
+1 −0 changelog.txt
+2 −2 common/src/main/java/com/microsoft/identity/common/nativeauth/internal/commands/SignUpStartCommand.kt
+13 −35 common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt
+9 −9 common/src/main/java/com/microsoft/identity/common/nativeauth/internal/util/CommandUtil.java
+1 −4 ...om/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/SignInOAuthStrategyTest.kt
+1 −2 ...m/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/SignUpOAuth2StrategyTest.kt
+2 −4 ...icrosoft/identity/common/internal/providers/microsoft/nativeauth/integration/scenario/SignUpScenarioTest.kt
+18 −25 common/src/test/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthControllerTest.kt
+0 −54 ...ain/com/microsoft/identity/common/java/nativeauth/commands/parameters/BaseSignUpStartCommandParameters.java
+36 −25 ...rc/main/com/microsoft/identity/common/java/nativeauth/commands/parameters/SignInStartCommandParameters.java
+0 −47 ...icrosoft/identity/common/java/nativeauth/commands/parameters/SignInStartUsingPasswordCommandParameters.java
+30 −4 ...rc/main/com/microsoft/identity/common/java/nativeauth/commands/parameters/SignUpStartCommandParameters.java
+0 −47 ...icrosoft/identity/common/java/nativeauth/commands/parameters/SignUpStartUsingPasswordCommandParameters.java
+2 −14 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthOAuth2Strategy.kt
+1 −24 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthRequestProvider.kt
+1 −1 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/interactors/SignInInteractor.kt
+1 −17 common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/interactors/SignUpInteractor.kt
+12 −12 common4j/src/test/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthRequestHandlerTest.kt
+1 −1 gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@
import com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordSubmitNewPasswordCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInResendCodeCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInStartCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInStartUsingPasswordCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInSubmitCodeCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInSubmitPasswordCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpResendCodeCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpStartCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpStartUsingPasswordCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitCodeCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitPasswordCommandParameters;
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitUserAttributesCommandParameters;
import com.microsoft.identity.nativeauth.NativeAuthPublicClientApplicationConfiguration;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -369,41 +365,6 @@ public static DeviceCodeFlowCommandParameters createDeviceCodeFlowCommandParamet
return commandParameters;
}

/**
* Creates command parameter for [{@link com.microsoft.identity.common.nativeauth.internal.commands.SignUpStartCommand}] of Native Auth.
* @param configuration PCA configuration
* @param tokenCache token cache for storing results
* @param username email address of the user
* @return Command parameter object
* @throws ClientException
*/
public static SignUpStartCommandParameters createSignUpStartCommandParameters(
@NonNull final NativeAuthPublicClientApplicationConfiguration configuration,
@NonNull final OAuth2TokenCache tokenCache,
@NonNull final String username,
final Map<String, String> userAttributes) {
final NativeAuthCIAMAuthority authority = ((NativeAuthCIAMAuthority) configuration.getDefaultAuthority());

return SignUpStartCommandParameters.builder()
.platformComponents(AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext()))
.applicationName(configuration.getAppContext().getPackageName())
.applicationVersion(getPackageVersion(configuration.getAppContext()))
.clientId(configuration.getClientId())
.isSharedDevice(configuration.getIsSharedDevice())
.redirectUri(configuration.getRedirectUri())
.oAuth2TokenCache(tokenCache)
.requiredBrokerProtocolVersion(configuration.getRequiredBrokerProtocolVersion())
.sdkType(SdkType.MSAL)
.sdkVersion(PublicClientApplication.getSdkVersion())
.powerOptCheckEnabled(configuration.isPowerOptCheckForEnabled())
.authority(authority)
.username(username)
.challengeType(configuration.getChallengeTypes())
.clientId(configuration.getClientId())
.userAttributes(userAttributes)
.build();
}

/**
* Creates command parameter for [{@link com.microsoft.identity.common.nativeauth.internal.commands.SignUpStartCommand}] of Native Auth when password is provided
* @param configuration PCA configuration
Expand All @@ -413,16 +374,16 @@ public static SignUpStartCommandParameters createSignUpStartCommandParameters(
* @return Command parameter object
* @throws ClientException
*/
public static SignUpStartUsingPasswordCommandParameters createSignUpStartUsingPasswordCommandParameters(
public static SignUpStartCommandParameters createSignUpStartCommandParameters(
@NonNull final NativeAuthPublicClientApplicationConfiguration configuration,
@NonNull final OAuth2TokenCache tokenCache,
@NonNull final String username,
@NonNull final char[] password,
@Nullable final char[] password,
Copy link
Contributor

Choose a reason for hiding this comment

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

update comment (line 373) to reflect the fact that password is optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The password is nullable but is still required as Java does not support default values. Developers have to specify all parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

This class is only used internally, but Kotlin classes (our state machine). In those cases, this field is optional. We've done the same for e.g. scopes parameter in other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Java does not have optional parameters. Optional parameters are simulated in Java by overloading functions. As this parameter is in the middle, it wouldn't be good style to overload function with reduced set of parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that this method isn't called from any Java class, and so we don't have to consider the non-optionality of this parameter. You can leave it like this however, that's also fine.

final Map<String, String> userAttributes) {

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

return SignUpStartUsingPasswordCommandParameters.builder()
return SignUpStartCommandParameters.builder()
.platformComponents(AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext()))
.applicationName(configuration.getAppContext().getPackageName())
.applicationVersion(getPackageVersion(configuration.getAppContext()))
Expand Down Expand Up @@ -583,47 +544,6 @@ public static SignUpSubmitPasswordCommandParameters createSignUpSubmitPasswordCo
.build();
}

/**
* Creates command parameter for [{@link com.microsoft.identity.common.nativeauth.internal.commands.SignInStartCommand}] of Native Auth.
* @param configuration PCA configuration
* @param tokenCache token cache for storing results
* @param username email address of the user
* @return Command parameter object
* @throws ClientException
*/
public static SignInStartCommandParameters createSignInStartCommandParameters(
@NonNull final NativeAuthPublicClientApplicationConfiguration configuration,
@NonNull final OAuth2TokenCache tokenCache,
@NonNull final String username) throws ClientException {
final AbstractAuthenticationScheme authenticationScheme = AuthenticationSchemeFactory.createScheme(
AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext()),
null
);

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

final SignInStartCommandParameters commandParameters = SignInStartCommandParameters.builder()
.platformComponents(AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext()))
.applicationName(configuration.getAppContext().getPackageName())
.applicationVersion(getPackageVersion(configuration.getAppContext()))
.clientId(configuration.getClientId())
.isSharedDevice(configuration.getIsSharedDevice())
.redirectUri(configuration.getRedirectUri())
.oAuth2TokenCache(tokenCache)
.requiredBrokerProtocolVersion(configuration.getRequiredBrokerProtocolVersion())
.sdkType(SdkType.MSAL)
.sdkVersion(PublicClientApplication.getSdkVersion())
.powerOptCheckEnabled(configuration.isPowerOptCheckForEnabled())
.authority(authority)
.username(username)
.authenticationScheme(authenticationScheme)
.clientId(configuration.getClientId())
.challengeType(configuration.getChallengeTypes())
.build();

return commandParameters;
}

/**
* Creates command parameter for [{@link com.microsoft.identity.common.nativeauth.internal.commands.SignInStartCommand}] of Native Auth using username and password
* @param configuration PCA configuration
Expand All @@ -634,11 +554,11 @@ public static SignInStartCommandParameters createSignInStartCommandParameters(
* @return Command parameter object
* @throws ClientException
*/
public static SignInStartUsingPasswordCommandParameters createSignInStartUsingPasswordCommandParameters(
public static SignInStartCommandParameters createSignInStartCommandParameters(
@NonNull final NativeAuthPublicClientApplicationConfiguration configuration,
@NonNull final OAuth2TokenCache tokenCache,
@NonNull final String username,
@NonNull final char[] password,
@Nullable final char[] password,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - update comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The password is nullable but is still required as Java does not support default values. Developers have to specify all parameters.

final List<String> scopes) throws ClientException {
final AbstractAuthenticationScheme authenticationScheme = AuthenticationSchemeFactory.createScheme(
AndroidPlatformComponentsFactory.createFromContext(configuration.getAppContext()),
Expand All @@ -647,7 +567,7 @@ public static SignInStartUsingPasswordCommandParameters createSignInStartUsingPa

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

final SignInStartUsingPasswordCommandParameters commandParameters = SignInStartUsingPasswordCommandParameters.builder()
final SignInStartCommandParameters commandParameters = SignInStartCommandParameters.builder()
.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 @@ -28,9 +28,7 @@ import com.microsoft.identity.client.exception.MsalException
import com.microsoft.identity.nativeauth.statemachine.results.GetAccountResult
import com.microsoft.identity.nativeauth.statemachine.results.ResetPasswordStartResult
import com.microsoft.identity.nativeauth.statemachine.results.SignInResult
import com.microsoft.identity.nativeauth.statemachine.results.SignInUsingPasswordResult
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResult
import com.microsoft.identity.nativeauth.statemachine.results.SignUpUsingPasswordResult


/**
Expand Down Expand Up @@ -71,89 +69,47 @@ interface INativeAuthPublicClientApplication : IPublicClientApplication {
* Sign in a user with a given username; Kotlin coroutines variant.
*
* @param username username of the account to sign in.
* @param password (Optional) password of the account to sign in.
* @param scopes (Optional) scopes to request during the sign in.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignInResult] see detailed possible return state under the object.
* @throws [MsalException] if an account is already signed in.
*/
suspend fun signIn(username: String, scopes: List<String>? = null): SignInResult
suspend fun signIn(username: String, password: CharArray? = null, scopes: List<String>? = null): SignInResult

/**
* Sign in a user with a given username; callback variant.
*
* @param username username of the account to sign in.
* @param password (Optional) password of the account to sign in.
* @param scopes (Optional) scopes to request during the sign in.
* @param callback [com.microsoft.identity.nativeauth.NativeAuthPublicClientApplication.SignInCallback] to receive the result.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignInResult] see detailed possible return state under the object.
* @throws [MsalException] if an account is already signed in.
*/
fun signIn(username: String, scopes: List<String>? = null, callback: NativeAuthPublicClientApplication.SignInCallback)

/**
* Sign in the account using username and password; Kotlin coroutines variant.
*
* @param username username of the account to sign in.
* @param password password of the account to sign in.
* @param scopes (Optional) list of scopes to request.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignInUsingPasswordResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
suspend fun signInUsingPassword(username: String, password: CharArray, scopes: List<String>? = null): SignInUsingPasswordResult

/**
* Sign in the account using username and password; callback variant.
*
* @param username username of the account to sign in.
* @param password password of the account to sign in.
* @param scopes (Optional) list of scopes to request.
* @param callback [com.microsoft.identity.nativeauth.NativeAuthPublicClientApplication.SignInUsingPasswordCallback] to receive the result.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignInUsingPasswordResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
fun signInUsingPassword(username: String, password: CharArray, scopes: List<String>? = null, callback: NativeAuthPublicClientApplication.SignInUsingPasswordCallback)
fun signIn(username: String, password: CharArray? = null, scopes: List<String>? = null, callback: NativeAuthPublicClientApplication.SignInCallback)

/**
* Sign up the account starting from a username; Kotlin coroutines variant.
*
* @param username username of the account to sign up.
* @param password (Optional) password of the account to sign up.
* @param attributes (Optional) user attributes to be used during account creation.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignUpResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
suspend fun signUp(username: String, attributes: UserAttributes? = null): SignUpResult
suspend fun signUp(username: String, password: CharArray? = null, attributes: UserAttributes? = null): SignUpResult

/**
* Sign up the account starting from a username; callback variant.
*
* @param username username of the account to sign up.
* @param password (Optional) password of the account to sign up.
* @param attributes (Optional) user attributes to be used during account creation.
* @param callback [com.microsoft.identity.nativeauth.NativeAuthPublicClientApplication.SignUpCallback] to receive the result.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignUpResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
fun signUp(username: String, attributes: UserAttributes? = null, callback: NativeAuthPublicClientApplication.SignUpCallback)

/**
* Sign up the account using username and password. Kotlin coroutines variant.
*
* @param username username of the account to sign up.
* @param password password of the account to sign up.
* @param attributes (Optional) user attributes to be used during account creation
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignUpUsingPasswordResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
suspend fun signUpUsingPassword(username: String, password: CharArray, attributes: UserAttributes? = null): SignUpUsingPasswordResult

/**
* Sign up the account using username and password; callback variant.
*
* @param username username of the account to sign up.
* @param password password of the account to sign up.
* @param attributes (Optional) user attributes to be used during account creation
* @param callback [com.microsoft.identity.nativeauth.NativeAuthPublicClientApplication.SignUpUsingPasswordCallback] to receive the result.
* @return [com.microsoft.identity.nativeauth.statemachine.results.SignUpUsingPasswordResult] see detailed possible return state under the object.
* @throws MsalClientException if an account is already signed in.
*/
fun signUpUsingPassword(username: String, password: CharArray, attributes: UserAttributes? = null, callback: NativeAuthPublicClientApplication.SignUpUsingPasswordCallback)
fun signUp(username: String, password: CharArray? = null, attributes: UserAttributes? = null, callback: NativeAuthPublicClientApplication.SignUpCallback)

/**
* Reset password for the account starting from a username; Kotlin coroutines variant.
Expand Down
Loading
Loading