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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new error type to AuthenticationError #820

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Auth0/AuthenticationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ public struct AuthenticationError: Auth0APIError {
public var isRefreshTokenDeleted: Bool {
return self.code == "invalid_grant"
&& self.localizedDescription == "The refresh_token was generated for a user who doesn't exist anymore."

}

// When the provided refresh token is invalid or expired
public var isInvalidRefreshToken: Bool {
return self.code == "invalid_grant"
&& self.localizedDescription == "Unknown or invalid refresh token."
}
Widcket marked this conversation as resolved.
Show resolved Hide resolved
/// When Auth0 denies access due to some misconfiguration or an error in an Action or Rule.
public var isAccessDenied: Bool {
return self.code == "access_denied"
Expand Down
17 changes: 14 additions & 3 deletions Auth0Tests/AuthenticationErrorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class AuthenticationErrorSpec: QuickSpec {
expect(error.isInvalidCredentials) == true
}

it("should detect invalid refresh token") {
it("should detect refresh token deleted") {
let values = [
"error": "invalid_grant",
"error_description": "The refresh_token was generated for a user who doesn't exist anymore."
Expand All @@ -364,6 +364,15 @@ class AuthenticationErrorSpec: QuickSpec {
expect(error.isRefreshTokenDeleted) == true
}

it("should detect invalid refresh token") {
let values = [
"error": "invalid_grant",
"error_description": "Unknown or invalid refresh token."
]
let error = AuthenticationError(info: values, statusCode: 403)
expect(error.isInvalidRefreshToken) == true
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the "should not match any custom error" and "should not match any known error" test cases as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review! Updated.

it("should detect invalid mfa token") {
let values = [
"error": "expired_token",
Expand Down Expand Up @@ -468,7 +477,8 @@ class AuthenticationErrorSpecSharedExamplesConfiguration: QuickConfiguration {
expect(error.isPasswordNotStrongEnough).to(beFalse(), description: "should not match password strength")
expect(error.isPasswordAlreadyUsed).to(beFalse(), description: "should not match password history")
expect(error.isInvalidCredentials).to(beFalse(), description: "should not match invalid credentials")
expect(error.isRefreshTokenDeleted).to(beFalse(), description: "should not match invalid refresh token")
expect(error.isRefreshTokenDeleted).to(beFalse(), description: "should not match refresh token deleted")
expect(error.isInvalidRefreshToken).to(beFalse(), description: "should not match invalid refresh token")
expect(error.isPasswordLeaked).to(beFalse(), description: "should not match password leaked")
expect(error.isLoginRequired).to(beFalse(), description: "should not match login required")
}
Expand Down Expand Up @@ -534,7 +544,8 @@ class AuthenticationErrorSpecSharedExamplesConfiguration: QuickConfiguration {
expect(error.isPasswordAlreadyUsed).to(beFalse(), description: "should not match password history")
expect(error.isAccessDenied).to(beFalse(), description: "should not match access denied")
expect(error.isInvalidCredentials).to(beFalse(), description: "should not match invalid credentials")
expect(error.isRefreshTokenDeleted).to(beFalse(), description: "should not match invalid refresh token")
expect(error.isRefreshTokenDeleted).to(beFalse(), description: "should not match refresh token deleted")
expect(error.isInvalidRefreshToken).to(beFalse(), description: "should not match invalid refresh token")
expect(error.isPasswordLeaked).to(beFalse(), description: "should not match password leaked")
expect(error.isLoginRequired).to(beFalse(), description: "should not match login required")
}
Expand Down