com.nimbusds.oauth2.sdk
Class AuthorizationResponse

java.lang.Object
  extended by com.nimbusds.oauth2.sdk.AuthorizationResponse
All Implemented Interfaces:
Message, Response
Direct Known Subclasses:
AuthorizationErrorResponse, AuthorizationSuccessResponse

public abstract class AuthorizationResponse
extends Object
implements Response

The base abstract class for authorisation success and error responses.

Related specifications:

Author:
Vladimir Dzhuvinov

Constructor Summary
protected AuthorizationResponse(URL redirectURI, State state)
          Creates a new authorisation response.
 
Method Summary
 URL getRedirectURI()
          Gets the base redirect URI.
 State getState()
          Gets the optional state.
static AuthorizationResponse parse(HTTPResponse httpResponse)
          Parses an authorisation response.
static AuthorizationResponse parse(URL uri)
          Parses an authorisation response.
static AuthorizationResponse parse(URL redirectURI, Map<String,String> params)
          Parses an authorisation response.
 HTTPResponse toHTTPResponse()
          Returns the HTTP response for this authorisation response.
abstract  Map<String,String> toParameters()
          Returns the parameters of this authorisation response.
abstract  URL toURI()
          Returns the URI representation (redirect 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
 

Constructor Detail

AuthorizationResponse

protected AuthorizationResponse(URL redirectURI,
                                State state)
Creates a new authorisation response.

Parameters:
redirectURI - The base redirect URI. Must not be null.
state - The state, null if not requested.
Method Detail

getRedirectURI

public URL getRedirectURI()
Gets the base redirect URI.

Returns:
The base redirect URI (without the appended error response parameters).

getState

public State getState()
Gets the optional state.

Returns:
The state, null if not requested.

toParameters

public abstract Map<String,String> toParameters()
                                         throws SerializeException
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.
Throws:
SerializeException - If this response couldn't be serialised to a parameters map.

toURI

public abstract URL toURI()
                   throws SerializeException
Returns the URI representation (redirect URI + fragment / query string) of this authorisation response.

Example URI:

 http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA
 &state=xyz
 &token_type=example
 &expires_in=3600
 

Returns:
The URI representation of this authorisation response.
Throws:
SerializeException - If this response couldn't be serialised to a URI.

toHTTPResponse

public HTTPResponse toHTTPResponse()
                            throws SerializeException
Returns the HTTP response for this authorisation response.

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 interface Response
Returns:
The HTTP response matching this authorisation response.
Throws:
SerializeException - If the response couldn't be serialised to an HTTP response.

parse

public static AuthorizationResponse parse(URL redirectURI,
                                          Map<String,String> params)
                                   throws ParseException
Parses an authorisation response.

Parameters:
redirectURI - The base redirect URI. Must not be null.
params - The response parameters to parse. Must not be null.
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(URL uri)
                                   throws ParseException
Parses an authorisation response.

Use a relative URI if the host, port and path details are not known:

 URL relUrl = new URL("http://?code=Qcb0Orv1...&state=af0ifjsldkj");
 AuthorizationResponse = AuthorizationResponse.parse(relURL);
 

Parameters:
uri - The URL to parse. May be absolute or relative, with a fragment or query string containing the authorisation response parameters. Must not be null.
Returns:
The authorisation success or error response.
Throws:
ParseException - If no authorisation response parameters were found in the URL.

parse

public static AuthorizationResponse parse(HTTPResponse httpResponse)
                                   throws ParseException
Parses an authorisation response.

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 be null.
Throws:
ParseException - If the HTTP response couldn't be parsed to an authorisation response.


Copyright © 2013 NimbusDS. All Rights Reserved.