-
Notifications
You must be signed in to change notification settings - Fork 424
[W-23059473] Introduce SFOAuthErrorCode enum for token endpoint error responses #4094
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/SFOAuthErrorCode.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /* | ||
| SFOAuthErrorCode.swift | ||
| SalesforceSDKCore | ||
|
|
||
| Copyright (c) 2026-present, salesforce.com, inc. All rights reserved. | ||
|
|
||
| Redistribution and use of this software in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
| * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
| and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| conditions and the following disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to | ||
| endorse or promote products derived from this software without specific prior written | ||
| permission of salesforce.com, inc. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
| IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
| FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | ||
| WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| import Foundation | ||
|
|
||
| /// Typed representation of the OAuth token endpoint error values defined by the | ||
| /// Salesforce server in OauthErrorCode.java (core/identity-common-api). | ||
| /// | ||
| /// Use ``from(_:)`` to parse the raw `error` string from a token endpoint response. | ||
| @objc public enum SFOAuthErrorCode: Int, CaseIterable { | ||
| case unknown = 0 | ||
| case accessDenied | ||
| case appBlocked | ||
| case appNotFound | ||
| case authorizationPending | ||
| case badJtiClaim | ||
| case appAttestationFailed | ||
| case appAttestationFailedRetry | ||
| case ecAppPolicyNotFound | ||
| case exceededRegistrationLimit | ||
| case failCloseAppBlocked | ||
| case failedRegistration | ||
| case immediateUnsuccessful | ||
| case installationError | ||
| case invalidAppAccess | ||
| case invalidAssertionType | ||
| case invalidBasicAuthHeader | ||
| case invalidClient | ||
| case invalidClientId | ||
| case invalidDpopProof | ||
| case invalidDistributionState | ||
| case invalidExpid | ||
| case invalidGrant | ||
| case invalidOtp | ||
| case invalidRequest | ||
| case invalidScope | ||
| case invalidSessionLevel | ||
| case invalidToken | ||
| case loginError | ||
| case oauthFlowDisabled | ||
| case oauthPolicyNotFound | ||
| case otpError | ||
| case redirectUriMissing | ||
| case redirectUriMismatch | ||
| case registrationError | ||
| case serverError | ||
| case serviceUnavailable | ||
| case slowDown | ||
| case systemDown | ||
| case unknownError | ||
| case unsupportedExpid | ||
| case unsupportedGrantType | ||
| case unsupportedResponseType | ||
| case unsupportedTokenType | ||
| case useDpopNonce | ||
|
|
||
| /// Returns the ``SFOAuthErrorCode`` whose wire value matches `string`, | ||
| /// or `.unknown` if `string` is nil, empty, or not recognized. | ||
| public static func from(_ string: String?) -> SFOAuthErrorCode { | ||
| guard let string = string, !string.isEmpty else { return .unknown } | ||
| return SFOAuthErrorCode.allCases.first { $0.wireValue == string } ?? .unknown | ||
| } | ||
| } | ||
|
|
||
| /// Objective-C–accessible bridge for ``SFOAuthErrorCode``. | ||
| /// Use `SFOAuthErrorCodeHelper.from(_:)` from Objective-C to parse error wire strings. | ||
| @objc public class SFOAuthErrorCodeHelper: NSObject { | ||
| /// Returns the integer raw value of the ``SFOAuthErrorCode`` matching `string`, | ||
| /// or the raw value of `.unknown` (0) if not recognized. | ||
| @objc public static func from(_ string: String?) -> NSInteger { | ||
| return SFOAuthErrorCode.from(string).rawValue | ||
| } | ||
| } | ||
|
|
||
| public extension SFOAuthErrorCode { | ||
| /// The wire string value sent in the token endpoint error JSON response. | ||
| /// Returns `nil` for `.unknown`. | ||
| var wireValue: String? { | ||
| switch self { | ||
| case .unknown: return nil | ||
| case .accessDenied: return "access_denied" | ||
| case .appBlocked: return "app_blocked" | ||
| case .appNotFound: return "app_not_found" | ||
| case .authorizationPending: return "authorization_pending" | ||
| case .badJtiClaim: return "bad_jti_claim" | ||
| case .appAttestationFailed: return "client_blocked" | ||
| case .appAttestationFailedRetry: return "client_blocked_retry" | ||
| case .ecAppPolicyNotFound: return "ecapp_policy_not_found" | ||
| case .exceededRegistrationLimit: return "exceeded_registration_limit" | ||
| case .failCloseAppBlocked: return "fail_close_app_blocked" | ||
| case .failedRegistration: return "failed_registration" | ||
| case .immediateUnsuccessful: return "immediate_unsuccessful" | ||
| case .installationError: return "installation_error" | ||
| case .invalidAppAccess: return "invalid_app_access" | ||
| case .invalidAssertionType: return "invalid_assertion_type" | ||
| case .invalidBasicAuthHeader: return "invalid_basic_auth_header" | ||
| case .invalidClient: return "invalid_client" | ||
| case .invalidClientId: return "invalid_client_id" | ||
| case .invalidDpopProof: return "invalid_dpop_proof" | ||
| case .invalidDistributionState: return "invalid_distribution_state" | ||
| case .invalidExpid: return "invalid_expid" | ||
| case .invalidGrant: return "invalid_grant" | ||
| case .invalidOtp: return "invalid_otp" | ||
| case .invalidRequest: return "invalid_request" | ||
| case .invalidScope: return "invalid_scope" | ||
| case .invalidSessionLevel: return "invalid_session_level" | ||
| case .invalidToken: return "invalid_token" | ||
| case .loginError: return "login_error" | ||
| case .oauthFlowDisabled: return "oauth_flow_disabled" | ||
| case .oauthPolicyNotFound: return "oauth_policy_not_found" | ||
| case .otpError: return "otp_error" | ||
| case .redirectUriMissing: return "redirect_uri_missing" | ||
| case .redirectUriMismatch: return "redirect_uri_mismatch" | ||
| case .registrationError: return "registration_error" | ||
| case .serverError: return "server_error" | ||
| case .serviceUnavailable: return "service_unavailable" | ||
| case .slowDown: return "slow_down" | ||
| case .systemDown: return "system_down" | ||
| case .unknownError: return "unknown_error" | ||
| case .unsupportedExpid: return "unsupported_expid" | ||
| case .unsupportedGrantType: return "unsupported_grant_type" | ||
| case .unsupportedResponseType: return "unsupported_response_type" | ||
| case .unsupportedTokenType: return "unsupported_token_type" | ||
| case .useDpopNonce: return "use_dpop_nonce" | ||
| @unknown default: return nil | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hardcoded now because the client-side is creating the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct — this is a client-side error, not a server wire value. The JWT response is malformed (wrong type), so the SDK generates the error locally rather than receiving it from the server.
jwt_launch_failedwas previously held in thekSFOAuthErrorTypeJWTLaunchFailedconstant (now deprecated), but since this error string is not a server-defined wire value it isn't inSFOAuthErrorCode. The raw string is used directly here since the deprecated constant is no longer the preferred reference.