Skip to content

Commit 14fc4ac

Browse files
authored
Add InvalidError for NativeAuth (#2297)
Corresponding PR in MSAL Repo : AzureAD/microsoft-authentication-library-for-android#2020
1 parent c0e8d76 commit 14fc4ac

File tree

12 files changed

+27
-32
lines changed

12 files changed

+27
-32
lines changed

common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ class NativeAuthMsalController : BaseNativeAuthController() {
404404
errorDescription = signUpStartApiResult.errorDescription
405405
)
406406
}
407-
is SignUpStartApiResult.InvalidEmail -> {
408-
SignUpCommandResult.InvalidEmail(
407+
is SignUpStartApiResult.InvalidUsername -> {
408+
INativeAuthCommandResult.InvalidUsername(
409409
error = signUpStartApiResult.error,
410410
errorDescription = signUpStartApiResult.errorDescription
411411
)

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/SignUpOAuth2StrategyTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class SignUpOAuth2StrategyTest {
206206
val signupResult = nativeAuthOAuth2Strategy.performSignUpStart(
207207
signUpStartCommandParameters
208208
)
209-
assertTrue(signupResult is SignUpStartApiResult.InvalidEmail)
209+
assertTrue(signupResult is SignUpStartApiResult.InvalidUsername)
210210
}
211211

212212
@Test

common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/INativeAuthCommandResult.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,14 @@ interface INativeAuthCommandResult {
7272
open val correlationId: String = DiagnosticContext.INSTANCE.threadCorrelationId,
7373
open val errorCodes: List<Int>? = null
7474
)
75+
76+
data class InvalidUsername(
77+
override val error: String?,
78+
override val errorDescription: String?,
79+
override val details: List<Map<String, String>>? = null,
80+
override val correlationId: String = DiagnosticContext.INSTANCE.threadCorrelationId,
81+
override val errorCodes: List<Int>? = null,
82+
val exception: Exception? = null
83+
) : Error(error, errorDescription, details, correlationId, errorCodes),
84+
INativeAuthCommandResult, SignInStartCommandResult, SignUpStartCommandResult, SignUpSubmitPasswordCommandResult, ResetPasswordStartCommandResult
7585
}

common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/SignUpCommandResult.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,6 @@ interface SignUpCommandResult {
9494
SignUpSubmitUserAttributesCommandResult,
9595
SignUpSubmitCodeCommandResult
9696

97-
/**
98-
* The signup operation cannot progress as the provided email address is invalid.
99-
*/
100-
data class InvalidEmail(
101-
val error: String,
102-
val errorDescription: String,
103-
val correlationId: String = DiagnosticContext.INSTANCE.threadCorrelationId //TODO: This initialisation will be removed as part of PBI https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2710164
104-
) : SignUpStartCommandResult, SignUpSubmitPasswordCommandResult
105-
10697
/**
10798
* The signup operation cannot progress as the provided password is not acceptable
10899
*/

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/requests/resetpassword/ResetPasswordStartRequest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ data class ResetPasswordStartRequest private constructor(
5454
): ResetPasswordStartRequest {
5555
// Check for empty Strings and empty Maps
5656
ArgUtils.validateNonNullArg(clientId, "clientId")
57-
ArgUtils.validateNonNullArg(username, "username")
5857
ArgUtils.validateNonNullArg(challengeType, "challengeType")
5958
ArgUtils.validateNonNullArg(requestUrl, "requestUrl")
6059
ArgUtils.validateNonNullArg(headers, "headers")

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/requests/signin/SignInInitiateRequest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ data class SignInInitiateRequest private constructor(
5353
headers: Map<String, String?>
5454
): SignInInitiateRequest {
5555
// Check for empty Strings and empty Maps
56-
ArgUtils.validateNonNullArg(username, "username")
5756
ArgUtils.validateNonNullArg(clientId, "clientId")
5857
ArgUtils.validateNonNullArg(challengeType, "challengeType")
5958
ArgUtils.validateNonNullArg(requestUrl, "requestUrl")

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/requests/signup/SignUpStartRequest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ data class SignUpStartRequest private constructor(
5757
headers: Map<String, String?>
5858
): SignUpStartRequest {
5959
// Check for empty Strings and empty Maps
60-
ArgUtils.validateNonNullArg(username, "username")
6160
ArgUtils.validateNonNullArg(clientId, "clientId")
6261
ArgUtils.validateNonNullArg(challengeType, "challengeType")
6362
ArgUtils.validateNonNullArg(requestUrl, "requestUrl")

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/signup/SignUpStartApiResponse.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import com.microsoft.identity.common.java.nativeauth.providers.IApiResponse
2929
import com.microsoft.identity.common.java.nativeauth.providers.responses.ApiErrorResult
3030
import com.microsoft.identity.common.java.nativeauth.util.isAttributeValidationFailed
3131
import com.microsoft.identity.common.java.nativeauth.util.isAuthNotSupported
32-
import com.microsoft.identity.common.java.nativeauth.util.isInvalidClient
33-
import com.microsoft.identity.common.java.nativeauth.util.isInvalidEmail
32+
import com.microsoft.identity.common.java.nativeauth.util.isInvalidUsername
3433
import com.microsoft.identity.common.java.nativeauth.util.isInvalidParameter
3534
import com.microsoft.identity.common.java.nativeauth.util.isPasswordBanned
3635
import com.microsoft.identity.common.java.nativeauth.util.isPasswordInvalid
@@ -41,7 +40,6 @@ import com.microsoft.identity.common.java.nativeauth.util.isPasswordTooWeak
4140
import com.microsoft.identity.common.java.nativeauth.util.isRedirect
4241
import com.microsoft.identity.common.java.nativeauth.util.isUnsupportedChallengeType
4342
import com.microsoft.identity.common.java.nativeauth.util.isUserAlreadyExists
44-
import com.microsoft.identity.common.java.nativeauth.util.isVerificationRequired
4543
import com.microsoft.identity.common.java.nativeauth.util.toAttributeList
4644
import java.net.HttpURLConnection
4745

@@ -79,8 +77,8 @@ data class SignUpStartApiResponse(
7977
errorDescription = errorDescription.orEmpty()
8078
)
8179
}
82-
errorCodes?.get(0).isInvalidParameter() and (errorDescription?.isInvalidEmail() == true) -> {
83-
SignUpStartApiResult.InvalidEmail(
80+
errorCodes?.get(0).isInvalidParameter() and (errorDescription?.isInvalidUsername() == true) -> {
81+
SignUpStartApiResult.InvalidUsername(
8482
error = error.orEmpty(),
8583
errorDescription = errorDescription.orEmpty()
8684
)

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/signup/SignUpStartApiResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sealed interface SignUpStartApiResult {
105105
/**
106106
* Signup start operation was started for a malformed email address.
107107
*/
108-
data class InvalidEmail(
108+
data class InvalidUsername(
109109
override val error: String,
110110
override val errorDescription: String
111111
): ApiErrorResult(

common4j/src/main/com/microsoft/identity/common/java/nativeauth/util/ApiErrorResponseUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ internal fun String?.isVerificationRequired(): Boolean {
110110
return this.contentEquals(other = "verification_required", ignoreCase = true)
111111
}
112112

113-
internal fun String?.isInvalidEmail(): Boolean {
113+
internal fun String?.isInvalidUsername(): Boolean {
114114
return (this?.contains(other = "username parameter is empty or not valid", ignoreCase = true) == true )
115115
}
116116

0 commit comments

Comments
 (0)