diff --git a/Auth0/AuthenticationError.swift b/Auth0/AuthenticationError.swift index 83e12942..e32023cb 100644 --- a/Auth0/AuthenticationError.swift +++ b/Auth0/AuthenticationError.swift @@ -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. diff --git a/Auth0Tests/AuthenticationErrorSpec.swift b/Auth0Tests/AuthenticationErrorSpec.swift index 7313dd36..3c3b3e18 100644 --- a/Auth0Tests/AuthenticationErrorSpec.swift +++ b/Auth0Tests/AuthenticationErrorSpec.swift @@ -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." @@ -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." @@ -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",