Class OAuthAuthorizationCodeFlow
Wraps Nimbus's AuthorizationRequest (for URL construction) + AuthorizationCodeGrant +
TokenRequest (for the exchange) + PKCE S256 challenge generation. buildAuthorizationUrl(String, CodeChallenge) emits a plain OAuth
2.0 authorization request; buildAuthenticationUrl(String, CodeChallenge, String, Consumer) emits an
OpenID Connect authentication request carrying a nonce. Supports RFC 8707 resource-indicator binding
via OAuthAuthorizationCodeFlow.Builder.resource(URI).
Usage
The flow does NOT manage state / PKCE-verifier storage; that's the caller's responsibility.
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptionbuildAuthenticationUrl(String state, com.nimbusds.oauth2.sdk.pkce.CodeChallenge codeChallenge, String nonce, Consumer<com.nimbusds.openid.connect.sdk.AuthenticationRequest.Builder> customizer) Builds an OpenID Connectauthorize?...URL carrying an OIDCnonceparameter.buildAuthorizationUrl(String state, com.nimbusds.oauth2.sdk.pkce.CodeChallenge codeChallenge) Builds theauthorize?...URL the user-agent should be redirected to.create()Static creator.Exchanges the authorization code returned by the IdP for an access token.Returns the authorization endpoint URL.Returns the client ID.Returns the redirect URI.Returns the requested scopes.Returns the token endpoint URL.
-
Constructor Details
-
OAuthAuthorizationCodeFlow
Constructor.- Parameters:
b- The builder.
-
-
Method Details
-
create
Static creator.- Returns:
- A new builder.
-
buildAuthorizationUrl
public URI buildAuthorizationUrl(String state, com.nimbusds.oauth2.sdk.pkce.CodeChallenge codeChallenge) Builds theauthorize?...URL the user-agent should be redirected to.- Parameters:
state- The opaquestateparameter (CSRF protection). Must not benull or blank.codeChallenge- The PKCE code challenge. Must not benull . Always uses S256.- Returns:
- The authorization URL.
-
buildAuthenticationUrl
public URI buildAuthenticationUrl(String state, com.nimbusds.oauth2.sdk.pkce.CodeChallenge codeChallenge, String nonce, Consumer<com.nimbusds.openid.connect.sdk.AuthenticationRequest.Builder> customizer) Builds an OpenID Connectauthorize?...URL carrying an OIDCnonceparameter.Unlike
buildAuthorizationUrl(String, CodeChallenge)(which emits a plain OAuth 2.0AuthorizationRequestwith nononce), this method emits an OIDCAuthenticationRequestso the IdP echoes the suppliednonceback inside the issued ID token. An OpenID Connect relying party stores thenoncebefore the redirect and verifies thenonceclaim on the returned ID token to defeat token replay.The configured
scope(...)set is used as-is; OIDC requires it to containopenid. The optionalcustomizerreceives the underlyingAuthenticationRequest.Builderso callers can set OIDC-specific parameters (e.g.prompt,max_age,acr_values) without this module needing to surface each one.- Parameters:
state- The opaquestateparameter (CSRF protection). Must not benull or blank.codeChallenge- The PKCE code challenge. Must not benull . Always uses S256.nonce- The OIDCnoncevalue. Must not benull or blank.customizer- Optional hook on theAuthenticationRequest.Builderfor OIDC-specific parameters. May benull .- Returns:
- The authorization URL.
-
exchange
Exchanges the authorization code returned by the IdP for an access token.- Parameters:
code- Thecodequery parameter from the IdP redirect. Must not benull or blank.codeVerifier- The PKCE verifier matching the challenge passed tobuildAuthorizationUrl(String, CodeChallenge). Must not benull .- Returns:
- The acquired token.
-
getAuthorizationEndpoint
Returns the authorization endpoint URL.- Returns:
- The endpoint.
-
getTokenEndpoint
Returns the token endpoint URL.- Returns:
- The endpoint.
-
getClientId
Returns the client ID.- Returns:
- The client ID.
-
getRedirectUri
Returns the redirect URI.- Returns:
- The redirect URI.
-
getScopes
Returns the requested scopes.- Returns:
- An unmodifiable view.
-