com.nimbusds.oauth2.sdk
Class AuthorizationRequest

java.lang.Object
  extended by com.nimbusds.oauth2.sdk.AuthorizationRequest
All Implemented Interfaces:
Message, Request
Direct Known Subclasses:
OIDCAuthorizationRequest

@Immutable
public class AuthorizationRequest
extends Object
implements Request

Authorisation request. Used to authenticate an end-user and request the end-user's consent to grant the client access to a protected resource. This class is immutable.

Extending classes may define additional request parameters as well as enforce tighter requirements on the base parameters.

Example HTTP request:

 https://server.example.com/authorize?
 response_type=code
 &client_id=s6BhdRkqt3
 &state=xyz
 &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
 

Related specifications:

Author:
Vladimir Dzhuvinov

Constructor Summary
AuthorizationRequest(ResponseType rt, ClientID clientID)
          Creates a new minimal authorisation request.
AuthorizationRequest(ResponseType rt, ClientID clientID, URL redirectURI, Scope scope, State state)
          Creates a new authorisation request.
 
Method Summary
 ClientID getClientID()
          Gets the client identifier.
 URL getRedirectURI()
          Gets the redirection URI.
 ResponseType getResponseType()
          Gets the response type.
 Scope getScope()
          Gets the scope.
 State getState()
          Gets the state.
static AuthorizationRequest parse(HTTPRequest httpRequest)
          Parses an authorisation request from the specified HTTP request.
static AuthorizationRequest parse(Map<String,String> params)
          Parses an authorisation request from the specified parameters.
static AuthorizationRequest parse(String query)
          Parses an authorisation request from the specified URL query string.
 HTTPRequest toHTTPRequest(HTTPRequest.Method method, URL url)
          Returns the matching HTTP request.
 HTTPRequest toHTTPRequest(URL url)
          Returns the matching HTTP request.
 Map<String,String> toParameters()
          Returns the parameters for this authorisation request.
 String toQueryString()
          Returns the URL query string for this authorisation request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthorizationRequest

public AuthorizationRequest(ResponseType rt,
                            ClientID clientID)
Creates a new minimal authorisation request.

Parameters:
rt - The response type. Corresponds to the response_type parameter. Must not be null.
clientID - The client identifier. Corresponds to the client_id parameter. Must not be null.

AuthorizationRequest

public AuthorizationRequest(ResponseType rt,
                            ClientID clientID,
                            URL redirectURI,
                            Scope scope,
                            State state)
Creates a new authorisation request.

Parameters:
rt - The response type. Corresponds to the response_type parameter. Must not be null.
clientID - The client identifier. Corresponds to the client_id parameter. Must not be null.
redirectURI - The redirection URI. Corresponds to the optional redirect_uri parameter. null if not specified.
scope - The request scope. Corresponds to the optional scope parameter. null if not specified.
state - The state. Corresponds to the recommended state parameter. null if not specified.
Method Detail

getResponseType

public ResponseType getResponseType()
Gets the response type. Corresponds to the response_type parameter.

Returns:
The response type.

getClientID

public ClientID getClientID()
Gets the client identifier. Corresponds to the client_id parameter.

Returns:
The client identifier.

getRedirectURI

public URL getRedirectURI()
Gets the redirection URI. Corresponds to the optional redirection_uri parameter.

Returns:
The redirection URI, null if not specified.

getScope

public Scope getScope()
Gets the scope. Corresponds to the optional scope parameter.

Returns:
The scope, null if not specified.

getState

public State getState()
Gets the state. Corresponds to the recommended state parameter.

Returns:
The state, null if not specified.

toParameters

public Map<String,String> toParameters()
                                throws SerializeException
Returns the parameters for this authorisation request.

Example parameters:

 response_type = code
 client_id     = s6BhdRkqt3
 state         = xyz
 redirect_uri  = https://client.example.com/cb
 

Returns:
The parameters.
Throws:
SerializeException - If this authorisation request couldn't be serialised to an parameters map.

toQueryString

public String toQueryString()
                     throws SerializeException
Returns the URL query string for this authorisation request.

Note that the '?' character preceding the query string in an URL is not included in the returned string.

Example URL query string:

 response_type=code
 &client_id=s6BhdRkqt3
 &state=xyz
 &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
 

Returns:
The URL query string.
Throws:
SerializeException - If this authorisation request couldn't be serialised to an URL query string.

toHTTPRequest

public HTTPRequest toHTTPRequest(HTTPRequest.Method method,
                                 URL url)
                          throws SerializeException
Returns the matching HTTP request.

Parameters:
method - The HTTP request method which can be GET or POST. Must not be null.
url - The URL of the HTTP endpoint for which the request is intended. Must not be null.
Returns:
The HTTP request.
Throws:
SerializeException - If the authorisation request message couldn't be serialised to an HTTP request.

toHTTPRequest

public HTTPRequest toHTTPRequest(URL url)
                          throws SerializeException
Description copied from interface: Request
Returns the matching HTTP request.

Specified by:
toHTTPRequest in interface Request
Parameters:
url - The URL of the HTTP endpoint for which the request is intended. Must not be null.
Returns:
The HTTP request.
Throws:
SerializeException - If the request message couldn't be serialised to an HTTP request.

parse

public static AuthorizationRequest parse(Map<String,String> params)
                                  throws ParseException
Parses an authorisation request from the specified parameters.

Example parameters:

 response_type = code
 client_id     = s6BhdRkqt3
 state         = xyz
 redirect_uri  = https://client.example.com/cb
 

Parameters:
params - The parameters. Must not be null.
Returns:
The authorisation request.
Throws:
ParseException - If the parameters couldn't be parsed to an authorisation request.

parse

public static AuthorizationRequest parse(String query)
                                  throws ParseException
Parses an authorisation request from the specified URL query string.

Example URL query string:

 response_type=code
 &client_id=s6BhdRkqt3
 &state=xyz
 &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
 

Parameters:
query - The URL query string. Must not be null.
Returns:
The authorisation request.
Throws:
ParseException - If the query string couldn't be parsed to an authorisation request.

parse

public static AuthorizationRequest parse(HTTPRequest httpRequest)
                                  throws ParseException
Parses an authorisation request from the specified HTTP request.

Example HTTP request (GET):

 https://server.example.com/authorize?
 response_type=code
 &client_id=s6BhdRkqt3
 &state=xyz
 &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
 

Parameters:
httpRequest - The HTTP request. Must not be null.
Returns:
The authorisation request.
Throws:
ParseException - If the HTTP request couldn't be parsed to an authorisation request.


Copyright © 2013 NimbusDS. All Rights Reserved.