Package com.nimbusds.oauth2.sdk
Class TokenRequest
-
@Immutable public class TokenRequest extends AbstractOptionallyIdentifiedRequest
Token request. Used to obtain anaccess token
and an optionalrefresh token
at the Token endpoint of the authorisation server. Supports custom request parameters.Example token request with an authorisation code grant:
POST /token HTTP/1.1 Host: server.example.com Content-Type: application/x-www-form-URIencoded Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW grant_type=authorization_code &code=SplxlOBeZQQYbYS6WxSbIA &redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb
Related specifications:
- OAuth 2.0 (RFC 6749), sections 4.1.3, 4.3.2, 4.4.2 and 6.
- Resource Indicators for OAuth 2.0 (RFC 8707)
- OAuth 2.0 Incremental Authorization (draft-ietf-oauth-incremental-authz-04)
-
-
Constructor Summary
Constructors Constructor Description TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant)
Creates a new token request with the specified client authentication.TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request with the specified client authentication.TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, Map<String,List<String>> customParams)
Creates a new token request with the specified client authentication and extension and custom parameters.TokenRequest(URI uri, AuthorizationGrant authzGrant)
Creates a new token request, without client authentication and a specified client identifier.TokenRequest(URI uri, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request, without client authentication and a specified client identifier.TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type).TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type).TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, RefreshToken existingGrant, Map<String,List<String>> customParams)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type) and extension and custom parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthorizationGrant
getAuthorizationGrant()
Returns the authorisation grant.List<String>
getCustomParameter(String name)
Returns the specified custom parameter included in the request body.Map<String,List<String>>
getCustomParameters()
Returns the additional custom parameters included in the request body.RefreshToken
getExistingGrant()
Returns the existing refresh token for incremental authorisation of a public client,null
if not specified.List<URI>
getResources()
Returns the resource server URI.Scope
getScope()
Returns the requested scope.static TokenRequest
parse(HTTPRequest httpRequest)
Parses a token request from the specified HTTP request.HTTPRequest
toHTTPRequest()
Returns the matching HTTP request.-
Methods inherited from class com.nimbusds.oauth2.sdk.AbstractOptionallyIdentifiedRequest
getClientID
-
Methods inherited from class com.nimbusds.oauth2.sdk.AbstractOptionallyAuthenticatedRequest
getClientAuthentication
-
Methods inherited from class com.nimbusds.oauth2.sdk.AbstractRequest
getEndpointURI
-
-
-
-
Constructor Detail
-
TokenRequest
public TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request with the specified client authentication.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.
-
TokenRequest
public TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, Map<String,List<String>> customParams)
Creates a new token request with the specified client authentication and extension and custom parameters.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.resources
- The resource URI(s),null
if not specified.customParams
- Custom parameters to be included in the request body, empty map ornull
if none.
-
TokenRequest
public TokenRequest(URI uri, ClientAuthentication clientAuth, AuthorizationGrant authzGrant)
Creates a new token request with the specified client authentication.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.
-
TokenRequest
public TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type).- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientID
- The client identifier,null
if not specified.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.
-
TokenRequest
public TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, RefreshToken existingGrant, Map<String,List<String>> customParams)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type) and extension and custom parameters.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientID
- The client identifier,null
if not specified.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.resources
- The resource URI(s),null
if not specified.existingGrant
- Existing refresh token for incremental authorisation of a public client,null
if not specified.customParams
- Custom parameters to be included in the request body, empty map ornull
if none.
-
TokenRequest
public TokenRequest(URI uri, ClientID clientID, AuthorizationGrant authzGrant)
Creates a new token request, with no explicit client authentication (may be present in the grant depending on its type).- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.clientID
- The client identifier,null
if not specified.authzGrant
- The authorisation grant. Must not benull
.
-
TokenRequest
public TokenRequest(URI uri, AuthorizationGrant authzGrant, Scope scope)
Creates a new token request, without client authentication and a specified client identifier.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.
-
TokenRequest
public TokenRequest(URI uri, AuthorizationGrant authzGrant)
Creates a new token request, without client authentication and a specified client identifier.- Parameters:
uri
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method will not be used.authzGrant
- The authorisation grant. Must not benull
.
-
-
Method Detail
-
getAuthorizationGrant
public AuthorizationGrant getAuthorizationGrant()
Returns the authorisation grant.- Returns:
- The authorisation grant.
-
getScope
public Scope getScope()
Returns the requested scope.- Returns:
- The requested scope,
null
if not specified.
-
getResources
public List<URI> getResources()
Returns the resource server URI.- Returns:
- The resource URI(s),
null
if not specified.
-
getExistingGrant
public RefreshToken getExistingGrant()
Returns the existing refresh token for incremental authorisation of a public client,null
if not specified.- Returns:
- The existing grant,
null
if not specified.
-
getCustomParameters
public Map<String,List<String>> getCustomParameters()
Returns the additional custom parameters included in the request body.Example:
resource=http://xxxxxx/PartyOData
- Returns:
- The additional custom parameters as a unmodifiable map, empty map if none.
-
getCustomParameter
public List<String> getCustomParameter(String name)
Returns the specified custom parameter included in the request body.- Parameters:
name
- The parameter name. Must not benull
.- Returns:
- The parameter value(s),
null
if not specified.
-
toHTTPRequest
public HTTPRequest toHTTPRequest()
Description copied from interface:Request
Returns the matching HTTP request.- Returns:
- The HTTP request.
-
parse
public static TokenRequest parse(HTTPRequest httpRequest) throws ParseException
Parses a token request from the specified HTTP request.- Parameters:
httpRequest
- The HTTP request. Must not benull
.- Returns:
- The token request.
- Throws:
ParseException
- If the HTTP request couldn't be parsed to a token request.
-
-