Skip to content

Commit

Permalink
Add more error pairs to isMultifactorCodeInvalid [SDK-4195] (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket committed Jun 20, 2023
1 parent 635ada1 commit eba79b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Auth0/AuthenticationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ public struct AuthenticationError: Auth0APIError {

/// When the MFA code sent is invalid or expired.
public var isMultifactorCodeInvalid: Bool {
return self.code == "a0.mfa_invalid_code" || self.code == "invalid_grant" && self.localizedDescription == "Invalid otp_code."
return self.code == "a0.mfa_invalid_code"
|| self.code == "invalid_grant" && self.localizedDescription == "Invalid otp_code."
|| self.code == "invalid_grant" && self.localizedDescription == "Invalid binding_code."
|| self.code == "invalid_grant" && self.localizedDescription == "MFA Authorization rejected."
}

/// When the MFA token is invalid or expired.
public var isMultifactorTokenInvalid: Bool {
return self.code == "expired_token" && self.localizedDescription == "mfa_token is expired" || self.code == "invalid_grant" && self.localizedDescription == "Malformed mfa_token"
return self.code == "expired_token" && self.localizedDescription == "mfa_token is expired"
|| self.code == "invalid_grant" && self.localizedDescription == "Malformed mfa_token"
}

/// When the password used for signup does not match the strength requirements of the connection.
Expand Down
22 changes: 20 additions & 2 deletions Auth0Tests/AuthenticationErrorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class AuthenticationErrorSpec: QuickSpec {
expect(error.isMultifactorEnrollRequired) == true
}

it("should detect mfa invalid code") {
it("should detect mfa invalid otp code") {
let values = [
"error": "a0.mfa_invalid_code",
"error_description": "Wrong or expired code."
Expand All @@ -292,7 +292,7 @@ class AuthenticationErrorSpec: QuickSpec {
expect(error.isMultifactorCodeInvalid) == true
}

it("should detect mfa invalid code oidc") {
it("should detect mfa invalid otp code oidc") {
let values = [
"error": "invalid_grant",
"error_description": "Invalid otp_code."
Expand All @@ -301,6 +301,24 @@ class AuthenticationErrorSpec: QuickSpec {
expect(error.isMultifactorCodeInvalid) == true
}

it("should detect mfa invalid binding code") {
let values = [
"error": "invalid_grant",
"error_description": "Invalid binding_code."
]
let error = AuthenticationError(info: values, statusCode: 401)
expect(error.isMultifactorCodeInvalid) == true
}

it("should detect mfa invalid recovery code") {
let values = [
"error": "invalid_grant",
"error_description": "MFA Authorization rejected."
]
let error = AuthenticationError(info: values, statusCode: 401)
expect(error.isMultifactorCodeInvalid) == true
}

it("should detect too many attempts") {
let values = [
"error": "too_many_attempts",
Expand Down

0 comments on commit eba79b5

Please sign in to comment.