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

Add more error pairs to isMultifactorCodeInvalid [SDK-4195] #779

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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