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
Merged

Conversation

SaurabhMSFT
Copy link
Contributor

@SaurabhMSFT SaurabhMSFT commented Jan 18, 2024

The signIn and signInUsingPassword methods have been refactored into one signIn method with optional password.
The signUp and signUpUsingPassword methods have been refactored into one signUp method with optional password.

PR for the common repo is AzureAD/microsoft-authentication-library-common-for-android#2284


/**
* Sign up the account starting from a username; callback variant.
*
* @param username username of the account to sign up.
* @param password password of the account to sign up.
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it explicit that this is optional, like we do for attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

scopes: List<String>?
): SignInUsingPasswordResult {
): SignInResult {
LogSession.logMethodCall(TAG, "${TAG}.signInUsingPassword")
return withContext(Dispatchers.IO) {
LogSession.logMethodCall(TAG, "${TAG}.signInUsingPassword.withContext")
Copy link
Contributor

Choose a reason for hiding this comment

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

Update log (and perhaps also in other places)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@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.

@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.

nativeAuthConfig,
nativeAuthConfig.oAuth2TokenCache,
username,
password,
attributes?.toMap()
attributes?.userAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what it is on line 781 in the previous version of the file.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we had an inconsistency between signUp and signUpUsingPassword when it comes to this field.
Could you validate that attributes?.userAttributes is the right way of doing this, and not attributes?.toMap(), by doing some E2E testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

SignUpStates.submitAttribute still uses toMap(), so this inconsistency needs to be fixed. Let's make sure we're not introducing a last minute bug in this flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

attributes?.userAttributes and attributes?.toMap() return the same value. I have changed the usage here to attributes?.toMap()

SaurabhMSFT added a commit to AzureAD/microsoft-authentication-library-common-for-android that referenced this pull request Jan 22, 2024
The signIn and signInUsingPassword methods have been refactored into one signIn method with optional password.
The signUp and signUpUsingPassword methods have been refactored into one signUp method with optional password.

PR for the MSAL repo is
AzureAD/microsoft-authentication-library-for-android#2010
@SammyO SammyO self-requested a review January 22, 2024 13:21
@@ -414,24 +280,26 @@ class NativeAuthPublicClientApplication(
* 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 password (Optional) password of the account to sign in.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be removed, as the optionality doesn't apply to Java call sites. Applies in different places in the code.

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 place where the optionality doesnot apply is in an internal package and not used from the Sample app. Optional in the doc should stay here as it provides meaningful information to the developer.

@SammyO SammyO self-requested a review January 22, 2024 16:09
@SaurabhMSFT SaurabhMSFT merged commit aad08a3 into dev Jan 22, 2024
9 checks passed
@SaurabhMSFT SaurabhMSFT deleted the saugautam/2774016 branch January 22, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants