Package com.nimbusds.oauth2.sdk
Class AuthorizationResponse
java.lang.Object
com.nimbusds.oauth2.sdk.AuthorizationResponse
- Direct Known Subclasses:
AuthorizationErrorResponse
,AuthorizationSuccessResponse
The base abstract class for authorisation success and error responses.
Related specifications:
- OAuth 2.0 (RFC 6749)
- OAuth 2.0 Multiple Response Type Encoding Practices 1.0
- OAuth 2.0 Form Post Response Mode 1.0
- Financial-grade API: JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)
- OAuth 2.0 Authorization Server Issuer Identification (RFC 9207)
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AuthorizationResponse
(URI redirectURI, com.nimbusds.jwt.JWT jwtResponse, ResponseMode rm) Creates a new JSON Web Token (JWT) secured authorisation response.protected
AuthorizationResponse
(URI redirectURI, State state, Issuer issuer, ResponseMode rm) Creates a new authorisation response. -
Method Summary
Modifier and TypeMethodDescriptionReturns the optional issuer.com.nimbusds.jwt.JWT
Returns the JSON Web Token (JWT) secured response.Returns the base redirection URI.Returns the optional explicit response mode.getState()
Returns the optional state.abstract ResponseMode
Determines the implied response mode.static AuthorizationResponse
parse
(HTTPRequest httpRequest) Parses an authorisation response from the specified HTTP request at the client redirection (callback) URI.static AuthorizationResponse
parse
(HTTPRequest httpRequest, JARMValidator jarmValidator) Parses and validates a JSON Web Token (JWT) secured authorisation response from the specified HTTP request at the client redirection (callback) URI.static AuthorizationResponse
parse
(HTTPResponse httpResponse) Parses an authorisation response from the specified initial HTTP 302 redirect response output at the authorisation endpoint.static AuthorizationResponse
parse
(HTTPResponse httpResponse, JARMValidator jarmValidator) Parses and validates a JSON Web Token (JWT) secured authorisation response from the specified initial HTTP 302 redirect response output at the authorisation endpoint.static AuthorizationResponse
Parses an authorisation response.static AuthorizationResponse
parse
(URI uri, JARMValidator jarmValidator) Parses and validates a JSON Web Token (JWT) secured authorisation response.static AuthorizationResponse
Parses an authorisation response.static AuthorizationResponse
Parses an authorisation response which may be JSON Web Token (JWT) secured.parseResponseParameters
(HTTPRequest httpRequest) Parses the relevant authorisation response parameters.Parses the relevant authorisation response parameters.Casts this response to an authorisation error response.Returns an HTTP request for this authorisation response.Returns an HTTP response for this authorisation response.Returns the parameters of this authorisation response.Casts this response to an authorisation success response.toURI()
Returns a URI representation (redirection URI + fragment / query string) of this authorisation response.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.nimbusds.oauth2.sdk.Response
indicatesSuccess
-
Constructor Details
-
AuthorizationResponse
Creates a new authorisation response.- Parameters:
redirectURI
- The base redirection URI. Must not benull
.state
- The state,null
if not requested.issuer
- The issuer,null
if not specified.rm
- The response mode,null
if not specified.
-
AuthorizationResponse
Creates a new JSON Web Token (JWT) secured authorisation response.- Parameters:
redirectURI
- The base redirection URI. Must not benull
.jwtResponse
- The JWT response. Must not benull
.rm
- The response mode,null
if not specified.
-
-
Method Details
-
getRedirectionURI
Returns the base redirection URI.- Returns:
- The base redirection URI.
-
getState
Returns the optional state.- Returns:
- The state,
null
if not requested or if the response is JWT-secured in which case the state parameter may be included as a JWT claim.
-
getIssuer
Returns the optional issuer.- Returns:
- The issuer,
null
if not specified.
-
getJWTResponse
Returns the JSON Web Token (JWT) secured response.- Returns:
- The JWT-secured response,
null
for a regular authorisation response.
-
getResponseMode
Returns the optional explicit response mode.- Returns:
- The response mode,
null
if not specified.
-
impliedResponseMode
Determines the implied response mode.- Returns:
- The implied response mode.
-
toParameters
Returns the parameters of this authorisation response.Example parameters (authorisation success):
access_token = 2YotnFZFEjr1zCsicMWpAA state = xyz token_type = example expires_in = 3600
- Returns:
- The parameters as a map.
-
toURI
Returns a URI representation (redirection URI + fragment / query string) of this authorisation response.Example URI:
https://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA &state=xyz &token_type=example &expires_in=3600
- Returns:
- A URI representation of this authorisation response.
-
toHTTPResponse
Returns an HTTP response for this authorisation response. Applies to thequery
orfragment
response mode using HTTP 302 redirection.Example HTTP response (authorisation success):
HTTP/1.1 302 Found Location: http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA &state=xyz &token_type=example &expires_in=3600
- Specified by:
toHTTPResponse
in interfaceResponse
- Returns:
- An HTTP response for this authorisation response.
- See Also:
-
toHTTPRequest
Returns an HTTP request for this authorisation response. Applies to theform_post
response mode.Example HTTP request (authorisation success):
GET /cb?code=SplxlOBeZQQYbYS6WxSbIA&state=xyz HTTP/1.1 Host: client.example.com
- Returns:
- An HTTP request for this authorisation response.
- See Also:
-
toSuccessResponse
Casts this response to an authorisation success response.- Returns:
- The authorisation success response.
-
toErrorResponse
Casts this response to an authorisation error response.- Returns:
- The authorisation error response.
-
parse
public static AuthorizationResponse parse(URI redirectURI, Map<String, List<String>> params) throws ParseExceptionParses an authorisation response.- Parameters:
redirectURI
- The base redirection URI. Must not benull
.params
- The response parameters to parse. Must not benull
.- Returns:
- The authorisation success or error response.
- Throws:
ParseException
- If the parameters couldn't be parsed to an authorisation success or error response.
-
parse
public static AuthorizationResponse parse(URI redirectURI, Map<String, List<String>> params, JARMValidator jarmValidator) throws ParseExceptionParses an authorisation response which may be JSON Web Token (JWT) secured.- Parameters:
redirectURI
- The base redirection URI. Must not benull
.params
- The response parameters to parse. Must not benull
.jarmValidator
- The validator of JSON Web Token (JWT) secured authorisation responses (JARM),null
if a plain response is expected.- Returns:
- The authorisation success or error response.
- Throws:
ParseException
- If the parameters couldn't be parsed to an authorisation success or error response, or if validation of the JWT secured response failed.
-
parse
Parses an authorisation response.Use a relative URI if the host, port and path details are not known:
URI relUrl = new URI("https:///?code=Qcb0Orv1...&state=af0ifjsldkj");
- Parameters:
uri
- The URI to parse. Can be absolute or relative, with a fragment or query string containing the authorisation response parameters. Must not benull
.- Returns:
- The authorisation success or error response.
- Throws:
ParseException
- If no authorisation response parameters were found in the URL.
-
parse
public static AuthorizationResponse parse(URI uri, JARMValidator jarmValidator) throws ParseException Parses and validates a JSON Web Token (JWT) secured authorisation response.Use a relative URI if the host, port and path details are not known:
URI relUrl = new URI("https:///?response=eyJhbGciOiJSUzI1NiIsI...");
- Parameters:
uri
- The URI to parse. Can be absolute or relative, with a fragment or query string containing the authorisation response parameters. Must not benull
.jarmValidator
- The validator of JSON Web Token (JWT) secured authorisation responses (JARM). Must not benull
.- Returns:
- The authorisation success or error response.
- Throws:
ParseException
- If no authorisation response parameters were found in the URL of if validation of the JWT response failed.
-
parse
Parses an authorisation response from the specified initial HTTP 302 redirect response output at the authorisation endpoint.Example HTTP response (authorisation success):
HTTP/1.1 302 Found Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA&state=xyz
- Parameters:
httpResponse
- The HTTP response to parse. Must not benull
.- Returns:
- The authorisation response.
- Throws:
ParseException
- If the HTTP response couldn't be parsed to an authorisation response.- See Also:
-
parse
public static AuthorizationResponse parse(HTTPResponse httpResponse, JARMValidator jarmValidator) throws ParseException Parses and validates a JSON Web Token (JWT) secured authorisation response from the specified initial HTTP 302 redirect response output at the authorisation endpoint.Example HTTP response (authorisation success):
HTTP/1.1 302 Found Location: https://client.example.com/cb?response=eyJhbGciOiJSUzI1...
- Parameters:
httpResponse
- The HTTP response to parse. Must not benull
.jarmValidator
- The validator of JSON Web Token (JWT) secured authorisation responses (JARM). Must not benull
.- Returns:
- The authorisation response.
- Throws:
ParseException
- If the HTTP response couldn't be parsed to an authorisation response or if validation of the JWT response failed.- See Also:
-
parse
Parses an authorisation response from the specified HTTP request at the client redirection (callback) URI. Applies to thequery
,fragment
andform_post
response modes.Example HTTP request (authorisation success):
GET /cb?code=SplxlOBeZQQYbYS6WxSbIA&state=xyz HTTP/1.1 Host: client.example.com
- Parameters:
httpRequest
- The HTTP request to parse. Must not benull
.- Returns:
- The authorisation response.
- Throws:
ParseException
- If the HTTP request couldn't be parsed to an authorisation response.- See Also:
-
parse
public static AuthorizationResponse parse(HTTPRequest httpRequest, JARMValidator jarmValidator) throws ParseException Parses and validates a JSON Web Token (JWT) secured authorisation response from the specified HTTP request at the client redirection (callback) URI. Applies to thequery.jwt
,fragment.jwt
andform_post.jwt
response modes.Example HTTP request (authorisation success):
GET /cb?response=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9... HTTP/1.1 Host: client.example.com
- Parameters:
httpRequest
- The HTTP request to parse. Must not benull
.jarmValidator
- The validator of JSON Web Token (JWT) secured authorisation responses (JARM). Must not benull
.- Returns:
- The authorisation response.
- Throws:
ParseException
- If the HTTP request couldn't be parsed to an authorisation response or if validation of the JWT response failed.- See Also:
-
parseResponseParameters
Parses the relevant authorisation response parameters. This method is intended for internal SDK usage only.- Parameters:
uri
- The URI to parse its query or fragment parameters. Must not benull
.- Returns:
- The authorisation response parameters.
- Throws:
ParseException
- If parsing failed.
-
parseResponseParameters
public static Map<String,List<String>> parseResponseParameters(HTTPRequest httpRequest) throws ParseException Parses the relevant authorisation response parameters. This method is intended for internal SDK usage only.- Parameters:
httpRequest
- The HTTP request. Must not benull
.- Returns:
- The authorisation response parameters.
- Throws:
ParseException
- If parsing failed.
-