T
- type of OAuth client configuration to be used.public class OAuth2Client<T extends OAuth2ClientConfiguration> extends Object implements OAuthClient
Modifier and Type | Field and Description |
---|---|
static String |
ACCESS_TOKEN
The access token issued by the authorization server.
|
protected Function<JsonValue,JsonValue,OAuthException> |
addExpireTime
Adds the actual time the token expires.
|
static String |
AUTHORIZATION_CODE
String used to verify the resource owner who granted the authorization at the authorization server.
|
static String |
AUTHORIZATION_HEADER
Authorization header.
|
static String |
BASIC_AUTH
Basic Auth.
|
static String |
BEARER_TOKEN
Token Type.
|
static String |
CLIENT_ID
Client Identifier.
|
static String |
CLIENT_SECRET
Client Password.
|
static String |
CODE
A type of response_type.
|
static String |
DATA
URI safe data that MUST not be modified by the client and
stored in the
DataStore . |
static String |
EXPIRE_TIME
Expire time.
|
static String |
EXPIRES_IN
Length of time token expires in.
|
static String |
GRANT_TYPE
Type of grant.
|
static String |
HTTP_GET
HTTP GET.
|
static String |
HTTP_POST
HTTP POST.
|
protected Handler |
httpHandler
Handler to be used to make http requests. |
static String |
LANDING_PAGE
URI where the user agent will be directed to after OAuth interaction is complete.
|
static String |
PKCE_CODE_CHALLENGE
PKCE code challenge parameter.
|
static String |
PKCE_CODE_CHALLENGE_METHOD
PKCE code challenge method.
|
static String |
PKCE_CODE_VERIFIER
PKCE code verifier parameter.
|
protected SecureRandom |
random
SecureRandom used to generate opaque, cryptographically secure strings. |
static String |
REDIRECT_URI
Uri to redirect the user agent back to from the authorization server.
|
static String |
REFRESH_TOKEN
Token used specifically to retrieve access tokens.
|
static String |
RESPONSE_TYPE
Value that determines the authorization processing flow to be used.
|
static String |
SCOPE
e.g.
|
static String |
STATE
Opaque value used to maintain state between the request and the callback.
|
protected TimeService |
timeService
TimeService used to handle token expire times. |
Constructor and Description |
---|
OAuth2Client(Handler httpHandler,
T config,
Clock clock,
SecureRandom random)
Constructs an OAuth2Client using a provided
Handler and OAuthClientConfiguration . |
OAuth2Client(Handler httpHandler,
T config,
TimeService timeService,
SecureRandom random)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addClientIdAndSecret(Request request,
Form form)
Adds the client id and client secret to a request
based on the determined type of authentication scheme.
|
protected String |
createAuthorizationState()
g
Generates a SecureRandom BigInteger as a String.
|
protected URI |
createAuthRedirectUri(String state)
Deprecated.
Use
OAuth2Client.createAuthRedirectUri(String, String) and specify a PKCE challenge. |
protected URI |
createAuthRedirectUri(String state,
String pkceChallenge)
Creates a
URI that the user agent will be redirected to for authentication and authorization. |
protected String |
createPkceVerifier()
Generates a secure opaque PKCE verifier value.
|
protected Function<Void,JsonValue,OAuthException> |
createPostAuthResponse(JsonValue storedData)
Creates the post auth response.
|
protected Request |
createRequestForTokenEndpoint(String code)
Deprecated.
Use
OAuth2Client.createAuthRedirectUri(String, String) and specify a PKCE verifier. |
protected Request |
createRequestForTokenEndpoint(String code,
String pkceVerifier)
Creates a
Request for the token endpoint of an identity provider. |
protected Request |
createRequestForTokenRefresh(JsonValue storedData)
Creates a
Request for the token refresh endpoint of an identity provider. |
protected Request |
createRequestForUserInfoEndpoint(String accessToken)
Creates a
Request for the user information endpoint of an identity provider. |
protected static String |
getAccessToken(JsonValue data)
Retrieves an access token from a
JsonValue . |
Promise<URI,OAuthException> |
getAuthRedirect(DataStore dataStore,
String data,
URI landingPage)
Return the URI that the user agent should be redirected to, to authenticate and authorize access.
|
protected T |
getConfig()
Gets the configuration for this
OAuthClient . |
protected static String |
getFirstValueOrNull(List<String> values)
Gets the first value out of the List.
|
Promise<? extends OAuth2SessionInfo,OAuthException> |
getSessionInfo(DataStore dataStore)
Validate whether an Auth Server session is still active and valid.
|
Promise<UserInfo,OAuthException> |
getUserInfo(DataStore dataStore)
Return the authenticated user's info from the external authentication server.
|
Promise<JsonValue,OAuthException> |
handlePostAuth(DataStore dataStore,
Map<String,List<String>> requestParameters)
Handle the data produced by the Auth Server as a result of a successful authentication and return the final
redirect to the landing page specified in the
OAuthClient.getAuthRedirect(DataStore, String, URI) call. |
protected static Function<Response,JsonValue,OAuthException> |
mapToJsonValue()
A
Function that handles a Response from an Auth Server
that returns the HTTP entity content as JsonValue, and throws an OAuthException if
the response is not successful (200 family status code). |
protected Function<JsonValue,UserInfo,OAuthException> |
mapToUserInfo()
Creates a
OAuth2UserInfo using a users raw profile. |
Promise<Void,OAuthException> |
refresh(DataStore dataStore)
Refreshes a token if it has expired.
|
protected Function<JsonValue,Void,OAuthException> |
storeResponse(DataStore dataStore)
Stores all the information received from an authentication or authorization server.
|
public static final String CLIENT_ID
public static final String CLIENT_SECRET
public static final String REDIRECT_URI
public static final String GRANT_TYPE
public static final String RESPONSE_TYPE
public static final String AUTHORIZATION_CODE
public static final String SCOPE
public static final String STATE
public static final String PKCE_CODE_CHALLENGE
public static final String PKCE_CODE_VERIFIER
public static final String PKCE_CODE_CHALLENGE_METHOD
public static final String ACCESS_TOKEN
public static final String REFRESH_TOKEN
public static final String CODE
public static final String EXPIRES_IN
public static final String DATA
DataStore
.public static final String LANDING_PAGE
public static final String EXPIRE_TIME
public static final String AUTHORIZATION_HEADER
public static final String BASIC_AUTH
public static final String BEARER_TOKEN
public static final String HTTP_GET
public static final String HTTP_POST
protected final Function<JsonValue,JsonValue,OAuthException> addExpireTime
protected final TimeService timeService
TimeService
used to handle token expire times.protected final SecureRandom random
SecureRandom
used to generate opaque, cryptographically secure strings.@Deprecated public OAuth2Client(Handler httpHandler, T config, TimeService timeService, SecureRandom random)
Handler
and OAuthClientConfiguration
.httpHandler
- Handler used to make Http calls to auth and resource servers.config
- configuration that will be used to drive oauth flow.timeService
- time service.random
- used to generate opaque, cryptographically secure strings.public OAuth2Client(Handler httpHandler, T config, Clock clock, SecureRandom random)
Handler
and OAuthClientConfiguration
.httpHandler
- Handler used to make Http calls to auth and resource servers.config
- configuration that will be used to drive oauth flow.clock
- clock instancerandom
- used to generate opaque, cryptographically secure strings.protected static Function<Response,JsonValue,OAuthException> mapToJsonValue()
Function
that handles a Response
from an Auth Server
that returns the HTTP entity content as JsonValue, and throws an OAuthException
if
the response is not successful (200 family status code).protected static final String getAccessToken(JsonValue data) throws OAuthException
JsonValue
.data
- the JsonValue that may contain an access token.OAuthException
- if no access token is found in the JsonValue.protected static final String getFirstValueOrNull(List<String> values)
values
- List<String>
protected final Function<JsonValue,UserInfo,OAuthException> mapToUserInfo()
OAuth2UserInfo
using a users raw profile.public Promise<URI,OAuthException> getAuthRedirect(DataStore dataStore, String data, URI landingPage)
OAuthClient
getAuthRedirect
in interface OAuthClient
dataStore
- The data store that contains information about the OAuth interaction.data
- A value which will be stored in the data store to be returned as part of the final landing
page redirect response, this MUST be URI safe.landingPage
- The final page a user agent should be sent following successful authentication.Promise
, with a type of URI
, suitable for redirecting the user agent for external
authentication and authorization and an Promise
, with a type of OAuthException
,
when an error occurs.public Promise<JsonValue,OAuthException> handlePostAuth(DataStore dataStore, Map<String,List<String>> requestParameters)
OAuthClient
OAuthClient.getAuthRedirect(DataStore, String, URI)
call.
Validate the request as secure. The returned JsonValue
response will also contain the data passed to
OAuthClient.getAuthRedirect(DataStore, String, URI)
.handlePostAuth
in interface OAuthClient
dataStore
- The data store that contains information about the OAuth interaction.requestParameters
- The request parameters containing the data produced by the external
authentication server.Promise
, with a type of JsonValue
, containing the landing page and the data value
that was stored in the data store during the OAuthClient.getAuthRedirect(DataStore, String, URI)
call; Promise
, with a type of OAuthException
, when an error occurs.public Promise<? extends OAuth2SessionInfo,OAuthException> getSessionInfo(DataStore dataStore)
OAuthClient
getSessionInfo
in interface OAuthClient
dataStore
- The data store that contains information about the OAuth interaction.Promise
, with a type of SessionInfo
, representing information about the session.
Promise
, with a type of OAuthException
, when an error occurs.public Promise<UserInfo,OAuthException> getUserInfo(DataStore dataStore)
OAuthClient
getUserInfo
in interface OAuthClient
dataStore
- The data store that contains information about the OAuth interaction.Promise
, with a type of UserInfo
, containing the available user info.
Promise
, with a type of OAuthException
, when an error occurs.public Promise<Void,OAuthException> refresh(DataStore dataStore)
OAuthClient
refresh
in interface OAuthClient
dataStore
- The data store that contains information about the OAuth interaction.Promise
If a new token has been retrieved, update the data store with the new token.
OAuthException
when an error occurs.protected URI createAuthRedirectUri(String state, String pkceChallenge)
URI
that the user agent will be redirected to for authentication and authorization.state
- opaque value used to prevent CSRF attacks.pkceChallenge
- opaque PKCE challenge used to prevent code interception/injection attacks.@Deprecated protected URI createAuthRedirectUri(String state)
OAuth2Client.createAuthRedirectUri(String, String)
and specify a PKCE challenge.URI
that the user agent will be redirected to for authentication and authorization.state
- opaque value used to prevent CSRF attacks.protected Request createRequestForTokenRefresh(JsonValue storedData)
Request
for the token refresh endpoint of an identity provider.protected Request createRequestForUserInfoEndpoint(String accessToken)
Request
for the user information endpoint of an identity provider.accessToken
- token required to retrieve user information.Request
for the user information endpoint.protected Request createRequestForTokenEndpoint(String code, String pkceVerifier)
Request
for the token endpoint of an identity provider.code
- e.g authorization_code, received from identity provider during
authentication and authorization phase.pkceVerifier
- the PKCE verifier, or null if PKCE not being used.Request
for the token endpoint.@Deprecated protected Request createRequestForTokenEndpoint(String code)
OAuth2Client.createAuthRedirectUri(String, String)
and specify a PKCE verifier.Request
for the token endpoint of an identity provider.code
- e.g authorization_code, received from identity provider during
authentication and authorization phase.Request
for the token endpoint.protected void addClientIdAndSecret(Request request, Form form)
request
- request to add authentication parameters.form
- which holds the additional parameters of the request.protected final Function<JsonValue,Void,OAuthException> storeResponse(DataStore dataStore)
dataStore
- data store in which to store the information.protected final Function<Void,JsonValue,OAuthException> createPostAuthResponse(JsonValue storedData)
storedData
- data store that contains information about the OAuth interaction.protected T getConfig()
OAuthClient
.protected String createAuthorizationState()
protected String createPkceVerifier()
Copyright © 2010-2018, ForgeRock All Rights Reserved.