Package com.nimbusds.oauth2.sdk
Class TokenRequest
Token request. Used to obtain an
access token
and an
optional refresh token
at the tokens endpoint of an
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-urlencoded 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)
- OAuth 2.0 Rich Authorization Requests (RFC 9396)
- Resource Indicators for OAuth 2.0 (RFC 8707)
- OAuth 2.0 Incremental Authorization (draft-ietf-oauth-incremental-authz)
- OpenID Connect Native SSO for Mobile Apps 1.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for constructing token requests. -
Constructor Summary
ConstructorDescriptionTokenRequest
(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant) Deprecated.TokenRequest
(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope) Creates a new token request with client authentication.TokenRequest
(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, DeviceSecret deviceSecret, Map<String, List<String>> customParams) Creates a new token request with client authentication and extension and custom parameters.TokenRequest
(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, Map<String, List<String>> customParams) Deprecated.TokenRequest
(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, Map<String, List<String>> customParams) Deprecated.TokenRequest
(URI endpoint, AuthorizationGrant authzGrant) Deprecated.TokenRequest
(URI endpoint, AuthorizationGrant authzGrant, Scope scope) Creates a new token request with no (explicit) client authentication, the client identifier is inferred from the authorisation grant.TokenRequest
(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant) Deprecated.TokenRequest
(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope) Creates a new token request with no (explicit) client authentication.TokenRequest
(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, RefreshToken existingGrant, DeviceSecret deviceSecret, Map<String, List<String>> customParams) Creates a new token request, with no (explicit) client authentication and extension and custom parameters.TokenRequest
(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, RefreshToken existingGrant, Map<String, List<String>> customParams) Deprecated.TokenRequest
(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, RefreshToken existingGrant, Map<String, List<String>> customParams) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionReturns the Rich Authorisation Request (RAR) details.Returns the authorisation grant.getCustomParameter
(String name) Returns the specified custom parameter included in the request body.Returns the additional custom parameters included in the request body.Returns the device secret for native SSO.Returns the existing refresh token for incremental authorisation of a public client.Returns the resource server URI.getScope()
Returns the requested scope.static TokenRequest
parse
(HTTPRequest httpRequest) Parses a token request from the specified HTTP request.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 Details
-
TokenRequest
public TokenRequest(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope) Creates a new token request with client authentication.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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
@Deprecated public TokenRequest(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, Map<String, List<String>> customParams) Deprecated.Creates a new token request with client authentication and extension and custom parameters.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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
@Deprecated public TokenRequest(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, Map<String, List<String>> customParams) Deprecated.Creates a new token request with client authentication and extension and custom parameters.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.authorizationDetails
- The Rich Authorisation Request (RAR) details,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
@Deprecated public TokenRequest(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant) Deprecated.Creates a new token request with client authentication.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.
-
TokenRequest
Creates a new token request with no (explicit) client authentication. The grant itself may be used to authenticate the client.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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
@Deprecated public TokenRequest(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<URI> resources, RefreshToken existingGrant, Map<String, List<String>> customParams) Deprecated.Creates a new token request, with no (explicit) client authentication and extension and custom parameters. The grant itself may be used to authenticate the client.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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
@Deprecated public TokenRequest(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, RefreshToken existingGrant, Map<String, List<String>> customParams) Deprecated.Creates a new token request, with no (explicit) client authentication and extension and custom parameters. The grant itself may be used to authenticate the client.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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.authorizationDetails
- The Rich Authorisation Request (RAR) details,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
Deprecated.Creates a new token request, with no (explicit) client authentication. The grant itself may be used to authenticate the client.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to be used.clientID
- The client identifier,null
if not specified.authzGrant
- The authorisation grant. Must not benull
.
-
TokenRequest
Creates a new token request with no (explicit) client authentication, the client identifier is inferred from the authorisation grant.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to be used.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.
-
TokenRequest
Deprecated.Creates a new token request with no (explicit) client authentication, the client identifier is inferred from the authorisation grant.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to be used.authzGrant
- The authorisation grant. Must not benull
.
-
TokenRequest
public TokenRequest(URI endpoint, ClientAuthentication clientAuth, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, DeviceSecret deviceSecret, Map<String, List<String>> customParams) Creates a new token request with client authentication and extension and custom parameters.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going be used.clientAuth
- The client authentication. Must not benull
.authzGrant
- The authorisation grant. Must not benull
.scope
- The requested scope,null
if not specified.authorizationDetails
- The Rich Authorisation Request (RAR) details,null
if not specified.resources
- The resource URI(s),null
if not specified.deviceSecret
- The device secret,null
if not specified.customParams
- Custom parameters to be included in the request body, empty map ornull
if none.
-
TokenRequest
public TokenRequest(URI endpoint, ClientID clientID, AuthorizationGrant authzGrant, Scope scope, List<AuthorizationDetail> authorizationDetails, List<URI> resources, RefreshToken existingGrant, DeviceSecret deviceSecret, Map<String, List<String>> customParams) Creates a new token request, with no (explicit) client authentication and extension and custom parameters. The grant itself may be used to authenticate the client.- Parameters:
endpoint
- The URI of the token endpoint. May benull
if thetoHTTPRequest()
method is not going to 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.authorizationDetails
- The Rich Authorisation Request (RAR) details,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.deviceSecret
- The device secret,null
if not specified.customParams
- Custom parameters to be included in the request body, empty map ornull
if none.
-
-
Method Details
-
getAuthorizationGrant
Returns the authorisation grant.- Returns:
- The authorisation grant.
-
getScope
Returns the requested scope. Corresponds to thescope
parameter.- Returns:
- The requested scope,
null
if not specified.
-
getAuthorizationDetails
Returns the Rich Authorisation Request (RAR) details. Corresponds to theauthorization_details
parameter.- Returns:
- The authorisation details,
null
if not specified.
-
getResources
Returns the resource server URI. Corresponds to theresource
parameter.- Returns:
- The resource URI(s),
null
if not specified.
-
getExistingGrant
Returns the existing refresh token for incremental authorisation of a public client. Corresponds to theexisting_grant
parameter.- Returns:
- The existing grant,
null
if not specified.
-
getDeviceSecret
Returns the device secret for native SSO. Corresponds to thedevice_secret
parameter.- Returns:
- The device secret,
null
if not specified.
-
getCustomParameters
Returns the additional custom parameters included in the request body.- Returns:
- The additional custom parameters as an unmodifiable map, empty map if none.
-
getCustomParameter
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
Description copied from interface:Request
Returns the matching HTTP request.- Returns:
- The HTTP request.
-
parse
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.
-