public class OAuth2
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
OAuth2.IdServiceResponse
Helper class to parse an identity service response.
|
static class |
OAuth2.LogoutReason |
static class |
OAuth2.OAuthFailedException
Exception thrown when the refresh flow fails.
|
static class |
OAuth2.TokenEndpointResponse
Helper class to parse a token refresh response.
|
static class |
OAuth2.TokenErrorResponse
Helper class to parse a token refresh error response.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
AUTHORIZATION |
protected static java.lang.String |
AUTHORIZATION_CODE |
protected static java.lang.String |
CLIENT_ID |
protected static java.lang.String |
CODE |
protected static java.lang.String |
CODE_CHALLENGE |
protected static java.lang.String |
CODE_VERIFIER |
protected static java.lang.String |
GRANT_TYPE |
protected static java.lang.String |
HYBRID_AUTH_CODE |
protected static java.lang.String |
OAUTH_AUTH_PATH |
protected static java.lang.String |
OAUTH_ENDPOINT_HEADLESS_FORGOT_PASSWORD
Endpoint path for Salesforce Identity API headless forgot password flow
|
protected static java.lang.String |
OAUTH_ENDPOINT_HEADLESS_INIT_PASSWORDLESS_LOGIN
Endpoint path for Salesforce Identity API initialize headless, password-less login flow
|
protected static java.lang.String |
OAUTH_ENDPOINT_HEADLESS_INIT_REGISTRATION
Endpoint path for Salesforce Identity API initialize headless registration flow
|
protected static java.lang.String |
OAUTH_TOKEN_PATH |
protected static java.lang.String |
REDIRECT_URI |
protected static java.lang.String |
RESPONSE_TYPE |
protected static java.lang.String |
SFDC_COMMUNITY_URL |
static java.text.DateFormat |
TIMESTAMP_FORMAT |
Constructor and Description |
---|
OAuth2() |
Modifier and Type | Method and Description |
---|---|
static Request.Builder |
addAuthorizationHeader(Request.Builder builder,
java.lang.String authToken)
Adds the authorization header to request builder.
|
static OAuth2.IdServiceResponse |
callIdentityService(HttpAccess httpAccessor,
java.lang.String identityServiceIdUrl,
java.lang.String authToken)
Calls the identity service to determine the username of the user and the mobile policy, given
their identity service ID and an access token.
|
static java.lang.String |
computeScopeParameter(java.lang.String[] scopes)
Computes the scope parameter from an array of scopes.
|
static OAuth2.TokenEndpointResponse |
exchangeCode(HttpAccess httpAccessor,
java.net.URI loginServer,
java.lang.String clientId,
java.lang.String code,
java.lang.String codeVerifier,
java.lang.String callbackUrl)
Exchange code for credentials.
|
static java.net.URI |
getAuthorizationUrl(boolean useWebServerAuthentication,
boolean useHybridAuthentication,
java.net.URI loginServer,
java.lang.String clientId,
java.lang.String callbackUrl,
java.lang.String[] scopes,
java.lang.String displayType,
java.lang.String codeChallenge,
java.util.Map<java.lang.String,java.lang.String> addlParams)
Builds the URL to the authorization web page for this login server.
|
static java.net.URI |
getFrontdoorUrl(java.net.URI url,
java.lang.String accessToken,
java.lang.String instanceURL,
java.util.Map<java.lang.String,java.lang.String> addlParams)
Deprecated.
Use
RestRequest.getRequestForSingleAccess(String) instead |
static java.lang.String |
getOpenIDToken(java.lang.String loginServer,
java.lang.String clientId,
java.lang.String refreshToken)
Fetches an OpenID token from the Salesforce backend.
|
static OAuth2.TokenEndpointResponse |
refreshAuthToken(HttpAccess httpAccessor,
java.net.URI loginServer,
java.lang.String clientId,
java.lang.String refreshToken,
java.util.Map<java.lang.String,java.lang.String> addlParams)
Gets a new auth token using the refresh token.
|
static void |
revokeRefreshToken(HttpAccess httpAccessor,
java.net.URI loginServer,
java.lang.String refreshToken)
Deprecated.
Will be removed in 13.0. Use
revokeRefreshToken(HttpAccess, URI, String, LogoutReason) instead. |
static void |
revokeRefreshToken(HttpAccess httpAccessor,
java.net.URI loginServer,
java.lang.String refreshToken,
OAuth2.LogoutReason reason)
Revokes the existing refresh token.
|
static OAuth2.TokenEndpointResponse |
swapJWTForTokens(HttpAccess httpAccessor,
java.net.URI loginServerUrl,
java.lang.String jwt)
Swaps a JWT for regular OAuth tokens.
|
protected static final java.lang.String CLIENT_ID
protected static final java.lang.String GRANT_TYPE
protected static final java.lang.String RESPONSE_TYPE
protected static final java.lang.String REDIRECT_URI
protected static final java.lang.String AUTHORIZATION_CODE
protected static final java.lang.String HYBRID_AUTH_CODE
protected static final java.lang.String CODE
protected static final java.lang.String CODE_CHALLENGE
protected static final java.lang.String CODE_VERIFIER
protected static final java.lang.String SFDC_COMMUNITY_URL
protected static final java.lang.String AUTHORIZATION
protected static final java.lang.String OAUTH_AUTH_PATH
protected static java.lang.String OAUTH_ENDPOINT_HEADLESS_INIT_PASSWORDLESS_LOGIN
protected static java.lang.String OAUTH_ENDPOINT_HEADLESS_INIT_REGISTRATION
protected static java.lang.String OAUTH_ENDPOINT_HEADLESS_FORGOT_PASSWORD
protected static final java.lang.String OAUTH_TOKEN_PATH
public static final java.text.DateFormat TIMESTAMP_FORMAT
public static java.net.URI getAuthorizationUrl(boolean useWebServerAuthentication, boolean useHybridAuthentication, java.net.URI loginServer, java.lang.String clientId, java.lang.String callbackUrl, java.lang.String[] scopes, java.lang.String displayType, java.lang.String codeChallenge, java.util.Map<java.lang.String,java.lang.String> addlParams)
useWebServerAuthentication
- True to use web server flow, False to use user agent flowuseHybridAuthentication
- True to use "hybrid" flowloginServer
- Base protocol and server to use (e.g. https://login.salesforce.com).clientId
- OAuth client ID.callbackUrl
- OAuth callback URL or redirect URL.scopes
- A list of OAuth scopes to request (e.g. {"visualforce", "api"}). If null,
the default OAuth scope is provided.displayType
- OAuth display type. If null, the default of 'touch' is used.codeChallenge
- Code challenge to use when using web server flowaddlParams
- Any additional parameters that may be added to the request.@Deprecated public static java.net.URI getFrontdoorUrl(java.net.URI url, java.lang.String accessToken, java.lang.String instanceURL, java.util.Map<java.lang.String,java.lang.String> addlParams)
RestRequest.getRequestForSingleAccess(String)
insteadurl
- the URL to "frontdoor"accessToken
- access token to use as sidinstanceURL
- instance url for the sidaddlParams
- additional paramaterspublic static java.lang.String computeScopeParameter(java.lang.String[] scopes)
scopes
- Array of scopes.public static OAuth2.TokenEndpointResponse exchangeCode(HttpAccess httpAccessor, java.net.URI loginServer, java.lang.String clientId, java.lang.String code, java.lang.String codeVerifier, java.lang.String callbackUrl) throws OAuth2.OAuthFailedException, java.io.IOException
httpAccessor
- HTTPAccess instance.loginServer
- Login server.clientId
- Client ID.code
- Code returned from the IDP.codeVerifier
- Code verifier used to generate 'code_challenge'.callbackUrl
- Callback URL.OAuth2.OAuthFailedException
- See OAuth2.OAuthFailedException
.java.io.IOException
- See IOException
.public static OAuth2.TokenEndpointResponse refreshAuthToken(HttpAccess httpAccessor, java.net.URI loginServer, java.lang.String clientId, java.lang.String refreshToken, java.util.Map<java.lang.String,java.lang.String> addlParams) throws OAuth2.OAuthFailedException, java.io.IOException
httpAccessor
- HttpAccess instance.loginServer
- Login server.clientId
- Client ID.refreshToken
- Refresh token.addlParams
- Additional parameters.OAuth2.OAuthFailedException
- See OAuth2.OAuthFailedException
.java.io.IOException
- See IOException
.public static void revokeRefreshToken(HttpAccess httpAccessor, java.net.URI loginServer, java.lang.String refreshToken)
revokeRefreshToken(HttpAccess, URI, String, LogoutReason)
instead.httpAccessor
- HttpAccess instance.loginServer
- Login server.refreshToken
- Refresh token.public static void revokeRefreshToken(HttpAccess httpAccessor, java.net.URI loginServer, java.lang.String refreshToken, OAuth2.LogoutReason reason)
httpAccessor
- HttpAccess instance.loginServer
- Login server.refreshToken
- Refresh token.reason
- The reason the refresh token is being revoked.public static OAuth2.TokenEndpointResponse swapJWTForTokens(HttpAccess httpAccessor, java.net.URI loginServerUrl, java.lang.String jwt) throws java.io.IOException, OAuth2.OAuthFailedException
httpAccessor
- HttpAccess instance.loginServerUrl
- The server (e.g. https://login.salesforce.com) that
the auth code was generated from.jwt
- JWT issued by the OAuth authorization flow.java.io.IOException
- See IOException
.OAuth2.OAuthFailedException
- See OAuth2.OAuthFailedException
.public static final OAuth2.IdServiceResponse callIdentityService(HttpAccess httpAccessor, java.lang.String identityServiceIdUrl, java.lang.String authToken) throws java.io.IOException
httpAccessor
- HttpAccessor instance.identityServiceIdUrl
- Identity service URL.authToken
- Access token.java.io.IOException
- See IOException
.public static final Request.Builder addAuthorizationHeader(Request.Builder builder, java.lang.String authToken)
builder
- Builder instance.authToken
- Access token.public static java.lang.String getOpenIDToken(java.lang.String loginServer, java.lang.String clientId, java.lang.String refreshToken)
loginServer
- Login server.clientId
- Client ID.refreshToken
- Refresh token.