OAuth2

open class OAuth2

Helper methods for common OAuth2 requests.

The typical OAuth2 flow is:

  1. The authorization flow is started by presenting the web-based authorization screen to the user. This will prompt him/her to login and to authorize our application. The result will be a callback with an authorization code, or an error.
  2. Use the authorization code from (a) with the token end point, to get access and refresh tokens, as well as other metadata.
  3. Use the access token from (b) to call the identity service, which will let us find out the user's username.
  4. Store the username, and refresh and access tokens somewhere safe (like the AccountManager).
  5. If the access token becomes invalid, use the refresh token to get another access token.
  6. If the refresh token becomes invalid, go back to the beginning.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
Helper class to parse an identity service response.
Link copied to clipboard
Link copied to clipboard
Exception thrown when the refresh flow fails.
Link copied to clipboard
Helper class to parse a token refresh response.
Link copied to clipboard
Helper class to parse a token refresh error response.

Properties

Link copied to clipboard
val ATTESTATION: String = "attestation"
OAuth 2.
Link copied to clipboard
val FRONTDOOR_URL_KEY: String = "frontdoor_uri"
Link copied to clipboard
val LOGIN_HINT: String = "login_hint"
Link copied to clipboard

Functions

Link copied to clipboard
open fun addAuthorizationHeader(builder: Request.Builder, authToken: String): Request.Builder
Adds the authorization header to request builder.
open fun addAuthorizationHeader(builder: Request.Builder, authToken: String, @Nullable tokenType: String): Request.Builder
Adds the authorization header to the request builder, choosing the scheme based on the token type.
Link copied to clipboard
open fun callIdentityService(httpAccessor: HttpAccess, identityServiceIdUrl: String, authToken: String): OAuth2.IdServiceResponse
open fun callIdentityService(httpAccessor: HttpAccess, identityServiceIdUrl: String, authToken: String, @Nullable tokenType: String, @Nullable credentialsIdentifier: String): OAuth2.IdServiceResponse
Calls the identity service to determine the username of the user and the mobile policy, given their identity service ID and an access token.
Link copied to clipboard
Computes the scope parameter from an array of scopes.
Link copied to clipboard
open fun exchangeCode(httpAccessor: HttpAccess, loginServer: URI, clientId: String, code: String, codeVerifier: String, callbackUrl: String): OAuth2.TokenEndpointResponse
Exchange code for credentials.
open fun exchangeCode(httpAccessor: HttpAccess, loginServer: URI, clientId: String, code: String, codeVerifier: String, callbackUrl: String, salesforceSdkManager: SalesforceSDKManager): OAuth2.TokenEndpointResponse
An internal, testable Salesforce Mobile SDK overload of exchangeCode.
open fun exchangeCode(httpAccessor: HttpAccess, loginServer: URI, clientId: String, code: String, codeVerifier: String, callbackUrl: String, salesforceSdkManager: SalesforceSDKManager, @Nullable credentialsIdentifier: String): OAuth2.TokenEndpointResponse
An internal, testable Salesforce Mobile SDK overload of exchangeCode that accepts a credentials identifier so DPoP proof can be attached when enabled.
Link copied to clipboard
open fun getAuthorizationUrl(useWebServerAuthentication: Boolean, useHybridAuthentication: Boolean, loginServer: URI, clientId: String, callbackUrl: String, scopes: Array<String>, displayType: String, codeChallenge: String, addlParams: Map<String, String>): URI
open fun getAuthorizationUrl(useWebServerAuthentication: Boolean, useHybridAuthentication: Boolean, loginServer: URI, clientId: String, callbackUrl: String, scopes: Array<String>, loginHint: String, displayType: String, codeChallenge: String, addlParams: Map<String, String>): URI
Builds the URL to the authorization web page for this login server.
Link copied to clipboard
open fun getFrontdoorUrl(url: URI, accessToken: String, instanceURL: String, addlParams: Map<String, String>): URI
Returns a 'frontdoor'ed URL Front door will authenticate client navigating to that URL using given access token
Link copied to clipboard
open fun getOpenIDToken(loginServer: String, @Nullable instanceServer: String, clientId: String, @Nullable communityId: String, @Nullable communityUrl: String, refreshToken: String): String
Fetches an OpenID token from the Salesforce backend.
Link copied to clipboard
open fun makeTokenEndpointRequest(httpAccessor: HttpAccess, loginServer: URI, formBodyBuilder: FormBody.Builder, salesforceSdkManager: SalesforceSDKManager): OAuth2.TokenEndpointResponse
open fun makeTokenEndpointRequest(httpAccessor: HttpAccess, loginServer: URI, formBodyBuilder: FormBody.Builder, salesforceSdkManager: SalesforceSDKManager, @Nullable credentialsIdentifier: String): OAuth2.TokenEndpointResponse

open fun makeTokenEndpointRequest(httpAccessor: HttpAccess, loginServer: URI, formBodyBuilder: FormBody.Builder, salesforceSdkManager: SalesforceSDKManager, @Nullable credentialsIdentifier: String, @Nullable tokenType: String): OAuth2.TokenEndpointResponse
Canonical implementation of the token-endpoint request.
Link copied to clipboard
Selects the server URI to target for token endpoint requests for the given user account.
open fun overrideLoginServerIfNeeded(loginServer: String, @Nullable instanceServer: String, @Nullable communityId: String, @Nullable communityUrl: String): URI
Selects the server URI to target for token endpoint requests.
Link copied to clipboard
open fun refreshAuthToken(httpAccessor: HttpAccess, loginServer: URI, clientId: String, refreshToken: String, addlParams: Map<String, String>): OAuth2.TokenEndpointResponse
open fun refreshAuthToken(httpAccessor: HttpAccess, loginServer: URI, clientId: String, refreshToken: String, addlParams: Map<String, String>, @Nullable credentialsIdentifier: String): OAuth2.TokenEndpointResponse
open fun refreshAuthToken(httpAccessor: HttpAccess, loginServer: URI, clientId: String, refreshToken: String, addlParams: Map<String, String>, @Nullable credentialsIdentifier: String, @Nullable tokenType: String): OAuth2.TokenEndpointResponse
Gets a new auth token using the refresh token.
Link copied to clipboard
open fun revokeRefreshToken(httpAccessor: HttpAccess, loginServer: URI, refreshToken: String, reason: OAuth2.LogoutReason)
Revokes the existing refresh token.
Link copied to clipboard
open fun swapJWTForTokens(httpAccessor: HttpAccess, loginServerUrl: URI, jwt: String): OAuth2.TokenEndpointResponse
Swaps a JWT for regular OAuth tokens.