Skip to content

Commit 0a6da71

Browse files
authored
Merge pull request #2754 from AzureAD/danilo/update-blocked-auth-method
Native auth: update auth method blocked error handling
2 parents af1020a + ab84ec9 commit 0a6da71

15 files changed

+31
-15
lines changed

MSAL/src/native_auth/network/errors/MSALNativeAuthESTSApiErrorCodes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ enum MSALNativeAuthESTSApiErrorCodes: Int {
3030
case invalidRequestParameter = 90100
3131
case resetPasswordRequired = 50142
3232
case invalidVerificationContact = 901001
33-
case authMethodBlocked = 550024
3433
}

MSAL/src/native_auth/network/errors/MSALNativeAuthSubErrorCode.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum MSALNativeAuthSubErrorCode: String, Decodable, Equatable, MSALNativeAuthUnk
3636
case introspectRequired = "introspect_required"
3737
case mfaRequired = "mfa_required"
3838
case jitRequired = "registration_required"
39+
case providerBlockedByRep = "provider_blocked_by_rep"
3940
case unknown
4041

4142
var isAnyPasswordError: Bool {
@@ -52,6 +53,7 @@ enum MSALNativeAuthSubErrorCode: String, Decodable, Equatable, MSALNativeAuthUnk
5253
.introspectRequired,
5354
.mfaRequired,
5455
.jitRequired,
56+
.providerBlockedByRep,
5557
.unknown:
5658
return false
5759
}

MSAL/src/native_auth/network/errors/jit/MSALNativeAuthJITChallengeOauth2ErrorCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ import Foundation
2626

2727
enum MSALNativeAuthJITChallengeOauth2ErrorCode: String, Decodable, MSALNativeAuthUnknownCaseProtocol {
2828
case invalidRequest = "invalid_request"
29+
case accessDenied = "access_denied"
2930
case unknown
3031
}

MSAL/src/native_auth/network/errors/jit/MSALNativeAuthJITChallengeResponseError.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct MSALNativeAuthJITChallengeResponseError: MSALNativeAuthResponseError {
3131
let errorCodes: [Int]?
3232
let errorURI: String?
3333
let innerErrors: [MSALNativeAuthInnerError]?
34+
let subError: MSALNativeAuthSubErrorCode?
3435
var correlationId: UUID?
3536

3637
enum CodingKeys: String, CodingKey {
@@ -39,6 +40,7 @@ struct MSALNativeAuthJITChallengeResponseError: MSALNativeAuthResponseError {
3940
case errorCodes = "error_codes"
4041
case errorURI = "error_uri"
4142
case innerErrors = "inner_errors"
43+
case subError = "suberror"
4244
case correlationId
4345
}
4446

@@ -48,13 +50,15 @@ struct MSALNativeAuthJITChallengeResponseError: MSALNativeAuthResponseError {
4850
errorCodes: [Int]? = nil,
4951
errorURI: String? = nil,
5052
innerErrors: [MSALNativeAuthInnerError]? = nil,
53+
subError: MSALNativeAuthSubErrorCode? = nil,
5154
correlationId: UUID? = nil
5255
) {
5356
self.error = error
5457
self.errorDescription = errorDescription
5558
self.errorCodes = errorCodes
5659
self.errorURI = errorURI
5760
self.innerErrors = innerErrors
61+
self.subError = subError
5862
self.correlationId = correlationId
5963
}
6064
}

MSAL/src/native_auth/network/errors/sign_in/MSALNativeAuthSignInChallengeOauth2ErrorCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ enum MSALNativeAuthSignInChallengeOauth2ErrorCode: String, Decodable, MSALNative
3030
case invalidGrant = "invalid_grant"
3131
case expiredToken = "expired_token"
3232
case unsupportedChallengeType = "unsupported_challenge_type"
33+
case accessDenied = "access_denied"
3334
case unknown
3435
}

MSAL/src/native_auth/network/responses/validator/jit/MSALNativeAuthJITResponseValidator.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ final class MSALNativeAuthJITResponseValidator: MSALNativeAuthJITResponseValidat
170170
private func handleFailedJITChallengeResult(
171171
error: MSALNativeAuthJITChallengeResponseError) -> MSALNativeAuthJITChallengeValidatedResponse {
172172
switch error.error {
173-
case .invalidRequest:
174-
if error.errorCodes?.contains(MSALNativeAuthESTSApiErrorCodes.authMethodBlocked.rawValue) == true {
173+
case .accessDenied:
174+
if error.subError == .providerBlockedByRep {
175175
let customErrorDescription = MSALNativeAuthErrorMessage.verificationContactBlocked + (error.errorDescription ?? "")
176176
return .error(.verificationContactBlocked(
177177
MSALNativeAuthJITChallengeResponseError(
@@ -182,7 +182,11 @@ final class MSALNativeAuthJITResponseValidator: MSALNativeAuthJITResponseValidat
182182
innerErrors: error.innerErrors,
183183
correlationId: error.correlationId
184184
)))
185-
} else if error.errorCodes?.contains(MSALNativeAuthESTSApiErrorCodes.invalidVerificationContact.rawValue) == true {
185+
} else {
186+
return .error(.unexpectedError(error))
187+
}
188+
case .invalidRequest:
189+
if error.errorCodes?.contains(MSALNativeAuthESTSApiErrorCodes.invalidVerificationContact.rawValue) == true {
186190
return .error(.invalidVerificationContact(error))
187191
} else {
188192
return .error(.unexpectedError(error))

MSAL/src/native_auth/network/responses/validator/sign_in/MSALNativeAuthSignInResponseValidator.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ final class MSALNativeAuthSignInResponseValidator: MSALNativeAuthSignInResponseV
173173
private func handleFailedSignInChallengeResult(
174174
error: MSALNativeAuthSignInChallengeResponseError) -> MSALNativeAuthSignInChallengeValidatedResponse {
175175
switch error.error {
176-
case .invalidRequest:
177-
if error.errorCodes?.contains(MSALNativeAuthESTSApiErrorCodes.authMethodBlocked.rawValue) == true {
176+
case .accessDenied:
177+
if error.subError == .providerBlockedByRep {
178178
let customErrorDescription = MSALNativeAuthErrorMessage.authMethodBlocked + (error.errorDescription ?? "")
179179
return .error(.authMethodBlocked(
180180
MSALNativeAuthSignInChallengeResponseError(
@@ -187,8 +187,10 @@ final class MSALNativeAuthSignInResponseValidator: MSALNativeAuthSignInResponseV
187187
correlationId: error.correlationId
188188
)))
189189
} else {
190-
return .error(.invalidRequest(error))
190+
return .error(.unexpectedError(error))
191191
}
192+
case .invalidRequest:
193+
return .error(.invalidRequest(error))
192194
case .unauthorizedClient:
193195
return .error(.unauthorizedClient(error))
194196
case .invalidGrant:

MSAL/src/native_auth/network/responses/validator/sign_up/MSALNativeAuthSignUpResponseValidator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ final class MSALNativeAuthSignUpResponseValidator: MSALNativeAuthSignUpResponseV
265265
case .unknown,
266266
.introspectRequired,
267267
.mfaRequired,
268+
.providerBlockedByRep,
268269
.jitRequired:
269270
return .unexpectedError(apiError)
270271
}

MSAL/src/native_auth/network/responses/validator/token/MSALNativeAuthTokenResponseValidator.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ final class MSALNativeAuthTokenResponseValidator: MSALNativeAuthTokenResponseVal
233233
case .userNotHaveAPassword,
234234
.invalidRequestParameter,
235235
.resetPasswordRequired,
236-
.authMethodBlocked,
237236
.invalidVerificationContact:
238237
return .generalError(apiError)
239238
}
@@ -249,7 +248,6 @@ final class MSALNativeAuthTokenResponseValidator: MSALNativeAuthTokenResponseVal
249248
.userNotHaveAPassword,
250249
.invalidRequestParameter,
251250
.resetPasswordRequired,
252-
.authMethodBlocked,
253251
.invalidVerificationContact:
254252
return .invalidRequest(apiError)
255253
}

MSAL/test/integration/native_auth/requests/jit/MSALNativeAuthJITChallengeIntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class MSALNativeAuthJITChallengeIntegrationTests: MSALNativeAuthIntegrationBaseT
9494
try await perform_testFail(
9595
endpoint: .jitChallenge,
9696
response: .authMethodBlocked,
97-
expectedError: Error(error: .invalidRequest, errorDescription: "AADSTS550024: Configuring multi-factor authentication method is blocked. Trace ID: ebec4d3c-253c-4668-aa73-7528f2140100 Correlation ID: f71d0f39-4412-44d3-a715-3e82508bf368 Timestamp: 2025-09-25 14:53:26Z", errorCodes: [550024], errorURI: nil, innerErrors: nil)
97+
expectedError: Error(error: .invalidRequest, errorDescription: "AADSTS550024: Configuring multi-factor authentication method is blocked. Trace ID: 48dc1336-6096-4167-ae1d-5bf3baa40400 Correlation ID: dbbcff90-8ad6-497f-aabb-73cc05ffdbdd Timestamp: 2025-10-07 12:59:45Z", errorCodes: [550024], errorURI: nil, innerErrors: nil)
9898
)
9999
}
100100

0 commit comments

Comments
 (0)