Package org.forgerock.oauth.clients.oidc
Class OpenIDConnectClient
java.lang.Object
org.forgerock.oauth.clients.oauth2.OAuth2Client<OpenIDConnectClientConfiguration>
org.forgerock.oauth.clients.oidc.OpenIDConnectClient
- All Implemented Interfaces:
OAuthClient
- Direct Known Subclasses:
AppleClient
OpenID Connect Client Implementation that supports the Authorization Code Grant Flow.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The acr values parameter.static final String
Audience identifier.static final String
The claims parameter.static final String
ID Token value associated with the authenticated session.static final String
Opaque value used to mitigate replay attacks.static final String
Parameter for an authentication request that is passing its parameters by value.static final String
Parameter for an authentication request that is passing its parameters by reference.static final String
Subject identifier.Fields inherited from class org.forgerock.oauth.clients.oauth2.OAuth2Client
ACCEPT_HEADER, ACCESS_TOKEN, addExpireTime, APPLICATION_JSON, AUTHORIZATION_CODE, AUTHORIZATION_HEADER, BASIC_AUTH, BEARER_TOKEN, CLIENT_ID, CLIENT_SECRET, clock, CODE, DATA, EXPIRE_TIME, EXPIRES_IN, GRANT_TYPE, HTTP_GET, HTTP_POST, httpHandler, LANDING_PAGE, PKCE_CODE_CHALLENGE, PKCE_CODE_CHALLENGE_METHOD, PKCE_CODE_VERIFIER, random, REDIRECT_URI, REFRESH_TOKEN, RESPONSE_MODE, RESPONSE_TYPE, SCOPE, STATE, TOKEN, TOKEN_TYPE, TOKEN_TYPE_HINT
-
Constructor Summary
ConstructorDescriptionOpenIDConnectClient
(Handler httpHandler, OpenIDConnectClientConfiguration config, Clock clock, SecureRandom random) Constructs an OpenIDConnectClient using a providedHandler
andOpenIDConnectClientConfiguration
.OpenIDConnectClient
(Handler httpHandler, OpenIDConnectClientConfiguration config, Clock clock, SecureRandom random, OpenIdResolverService resolverService, OpenIdResolverServiceConfigurator serviceConfigurator) Constructs an OpenIDConnectClient using a providedHandler
,OpenIDConnectClientConfiguration
,OpenIdResolverService
andOpenIdResolverServiceConfigurator
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Form
buildQuery
(String nonce) Creates the query that will be passed to the request.protected URI
createAuthRedirectUri
(String state, String nonce) Deprecated.protected URI
createAuthRedirectUri
(String state, String pkceChallenge, String nonce) Creates aURI
that the user agent will be redirected to for authentication and authorization.protected URI
createAuthRedirectUri
(String state, String pkceChallenge, String nonce, DataStore dataStore) Creates aURI
that the user agent will be redirected to for authentication and authorization.protected String
Generates a nonce value.protected final UserInfo
createUserInfoFromIdTokenJwtClaims
(JwtClaimsSet jwtClaims) Creates anOpenIDConnectUserInfo
object from id_token jwt Claims.getAuthRedirect
(DataStore dataStore, String data, URI landingPage) Return the URI that the user agent should be redirected to, to authenticate and authorize access.protected final JwtClaimsSet
getJwtClaimsSet
(DataStore dataStore) Retrieves the claims set from the data store.protected static final String
Returns the nonce value store in the data store.Promise<? extends OAuth2SessionInfo,
OAuthException> getSessionInfo
(DataStore dataStore) Validate whether an Auth Server session is still active and valid.getUserInfo
(DataStore dataStore) Return the authenticated user's info from the external authentication server.Handle the data produced by the Auth Server as a result of a successful authentication and return the final redirect to the mobile device.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 theOAuthClient.getAuthRedirect(DataStore, String, URI)
call.protected static final JsonValue
jwtClaimsAsJsonValue
(JwtClaimsSet jwtClaims) Returns the jwt claims as aJsonValue
.protected final Function<JsonValue,
UserInfo, OAuthException> mapToUserInfo
(JwtClaimsSet jwtClaims) Maps a retrieved raw profile from the user info endpoint to anOpenIDConnectUserInfo
object.protected final Function<JsonValue,
JsonValue, OAuthException> validateSub
(DataStore dataStore) Validates the sub Claim in the UserInfo Response is an exact match to the sub Claim in the ID Token.Methods inherited from class org.forgerock.oauth.clients.oauth2.OAuth2Client
createAuthorizationState, createAuthRedirectUri, createPkceVerifier, createPostAuthResponse, createPostResponse, createRequestForIntrospectEndpoint, createRequestForTokenEndpoint, createRequestForTokenEndpoint, createRequestForTokenRefresh, createRequestForUserInfoEndpoint, getAccessToken, getAccessTokenInfo, getConfig, getFirstValueOrNull, getTokenEndpointHandler, mapToJsonValue, mapToUserInfo, refresh, storeResponse, throwIfNoClientSecret, validateClientId
-
Field Details
-
ACR_VALUES
The acr values parameter.- See Also:
-
CLAIMS
The claims parameter.- See Also:
-
ID_TOKEN
ID Token value associated with the authenticated session.- See Also:
-
NONCE
Opaque value used to mitigate replay attacks.- See Also:
-
SUB
Subject identifier.- See Also:
-
AUD
Audience identifier.- See Also:
-
REQUEST_URI
Parameter for an authentication request that is passing its parameters by reference.- See Also:
-
REQUEST
Parameter for an authentication request that is passing its parameters by value.- See Also:
-
-
Constructor Details
-
OpenIDConnectClient
public OpenIDConnectClient(Handler httpHandler, OpenIDConnectClientConfiguration config, Clock clock, SecureRandom random) Constructs an OpenIDConnectClient using a providedHandler
andOpenIDConnectClientConfiguration
.- Parameters:
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
-SecureRandom
.
-
OpenIDConnectClient
public OpenIDConnectClient(Handler httpHandler, OpenIDConnectClientConfiguration config, Clock clock, SecureRandom random, OpenIdResolverService resolverService, OpenIdResolverServiceConfigurator serviceConfigurator) Constructs an OpenIDConnectClient using a providedHandler
,OpenIDConnectClientConfiguration
,OpenIdResolverService
andOpenIdResolverServiceConfigurator
.- Parameters:
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
-SecureRandom
.resolverService
-OpenIdResolverServiceImpl
. OpenID resolvers instance that also contains the JwksStoreCache. By providing the same instance of resolvers for every OpenIdConnectClient the same JwksCache will be used.serviceConfigurator
-OpenIdResolverServiceConfigurator
.
-
-
Method Details
-
jwtClaimsAsJsonValue
Returns the jwt claims as aJsonValue
.- Parameters:
jwtClaims
- jwt claims.- Returns:
- jwt claims as a JsonValue.
- Throws:
OAuthException
- when object mapper error converting jwt claims to Map.
-
getNonce
Returns the nonce value store in the data store.- Parameters:
storedData
- the stored authentication and authorization information.- Returns:
- nonce
-
getAuthRedirect
public Promise<URI,OAuthException> getAuthRedirect(DataStore dataStore, String data, URI landingPage) Description copied from interface:OAuthClient
Return the URI that the user agent should be redirected to, to authenticate and authorize access.- Specified by:
getAuthRedirect
in interfaceOAuthClient
- Overrides:
getAuthRedirect
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
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.- Returns:
Promise
, with a type ofURI
, suitable for redirecting the user agent for external authentication and authorization and anPromise
, with a type ofOAuthException
, when an error occurs.
-
handlePostAuth
public Promise<JsonValue,OAuthException> handlePostAuth(DataStore dataStore, Map<String, List<String>> requestParameters) Description copied from interface:OAuthClient
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 theOAuthClient.getAuthRedirect(DataStore, String, URI)
call. Validate the request as secure. The returnedJsonValue
response will also contain the data passed toOAuthClient.getAuthRedirect(DataStore, String, URI)
.- Specified by:
handlePostAuth
in interfaceOAuthClient
- Overrides:
handlePostAuth
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
dataStore
- The data store that contains information about the OAuth interaction.requestParameters
- The request parameters containing the data produced by the external authentication server.- Returns:
Promise
, with a type ofJsonValue
, containing the landing page and the data value that was stored in the data store during theOAuthClient.getAuthRedirect(DataStore, String, URI)
call;Promise
, with a type ofOAuthException
, when an error occurs.
-
handleNativePostAuth
public Promise<JsonValue,OAuthException> handleNativePostAuth(Context context, DataStore dataStore, Map<String, List<String>> parameters) Description copied from interface:OAuthClient
Handle the data produced by the Auth Server as a result of a successful authentication and return the final redirect to the mobile device. Validate the request as secure. The returnedJsonValue
response will also contain the data passed toOAuthClient.getAuthRedirect(DataStore, String, URI)
.- Specified by:
handleNativePostAuth
in interfaceOAuthClient
- Overrides:
handleNativePostAuth
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
context
- Context chain used to keep a relationship between requests (tracking)dataStore
- The data store that contains information about the OAuth interaction.parameters
- The parameters containing the data sent by the external mobile device.- Returns:
Promise
, with a type ofJsonValue
, containing the data value that was stored in the data store during theOAuthClient.getAuthRedirect(DataStore, String, URI)
call;Promise
, with a type ofOAuthException
, when an error occurs.
-
getUserInfo
Description copied from interface:OAuthClient
Return the authenticated user's info from the external authentication server.- Specified by:
getUserInfo
in interfaceOAuthClient
- Overrides:
getUserInfo
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
dataStore
- The data store that contains information about the OAuth interaction.- Returns:
Promise
, with a type ofUserInfo
, containing the available user info.Promise
, with a type ofOAuthException
, when an error occurs.
-
getSessionInfo
Description copied from interface:OAuthClient
Validate whether an Auth Server session is still active and valid.- Specified by:
getSessionInfo
in interfaceOAuthClient
- Overrides:
getSessionInfo
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
dataStore
- The data store that contains information about the OAuth interaction.- Returns:
Promise
, with a type ofSessionInfo
, representing information about the session.Promise
, with a type ofOAuthException
, when an error occurs.
-
validateSub
Validates the sub Claim in the UserInfo Response is an exact match to the sub Claim in the ID Token.- Parameters:
dataStore
- data store holding authentication and authorization information.- Returns:
- the JsonValue that contained the nonce to inspect;
-
mapToUserInfo
Maps a retrieved raw profile from the user info endpoint to anOpenIDConnectUserInfo
object.- Parameters:
jwtClaims
- jwt claims from an id_token.- Returns:
- the raw profile retrieved as an
OpenIDConnectUserInfo
object.
-
createUserInfoFromIdTokenJwtClaims
protected final UserInfo createUserInfoFromIdTokenJwtClaims(JwtClaimsSet jwtClaims) throws OAuthException Creates anOpenIDConnectUserInfo
object from id_token jwt Claims.- Parameters:
jwtClaims
- jwt claims from an id_token.- Returns:
- OpenIDConnectUserInfo object.
- Throws:
OAuthException
- if error occurs while converting theJwtClaimsSet
toJsonValue
.
-
createAuthRedirectUri
Creates aURI
that the user agent will be redirected to for authentication and authorization.- Parameters:
state
- opaque value used to prevent CSRF attacks.pkceChallenge
- opaque value used to prevent code interception/injection attacks.nonce
- opaque value used to mitigate replay attacks of an id_token.- Returns:
- URI
-
createAuthRedirectUri
protected URI createAuthRedirectUri(String state, String pkceChallenge, String nonce, DataStore dataStore) throws OAuthException Creates aURI
that the user agent will be redirected to for authentication and authorization.- Parameters:
state
- opaque value used to prevent CSRF attacks.pkceChallenge
- opaque value used to prevent code interception/injection attacks.nonce
- opaque value used to mitigate replay attacks of an id_token.dataStore
- The data store that contains information about the OAuth interaction.- Returns:
- URI
- Throws:
OAuthException
- when an error occurs while retrieving the data.
-
buildQuery
Creates the query that will be passed to the request. This method is meant to tbe overridden when adding additional fields to the query is necessary.- Parameters:
nonce
- opaque value used to mitigate replay attacks of an id_token.- Returns:
- the query
-
createAuthRedirectUri
Deprecated.UsecreateAuthRedirectUri(String, String, String)
and specify a PKCE challenge.Creates aURI
that the user agent will be redirected to for authentication and authorization.- Overrides:
createAuthRedirectUri
in classOAuth2Client<OpenIDConnectClientConfiguration>
- Parameters:
state
- opaque value used to prevent CSRF attacks.nonce
- opaque value used to mitigate replay attacks of an id_token.- Returns:
- URI
-
createNonce
Generates a nonce value.- Returns:
- nonce value.
-
getJwtClaimsSet
Retrieves the claims set from the data store.- Parameters:
dataStore
- the data store.- Returns:
- JwtClaimSet set of claims authorized by the user.
- Throws:
OAuthException
- when error occurs while retrieving the claims set.
-
createAuthRedirectUri(String, String, String)
and specify a PKCE challenge.