Class TokenRequest
- java.lang.Object
-
- com.authlete.common.dto.TokenRequest
-
- All Implemented Interfaces:
Serializable
public class TokenRequest extends Object implements Serializable
Request to Authlete's/auth/tokenAPI.parameters(REQUIRED)-
OAuth 2.0 token request parameters which are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.
The value of
"parameters"is the entire entity body (which is formatted inapplication/x-www-form-urlencoded) of the request from the client application. clientId(OPTIONAL)-
The client ID extracted from
Authorizationheader of the token request from the client application.If the token endpoint of the service implementation supports Basic Authentication as a means of client authentication, and the request from the client application contained its client ID in
Authorizationheader, the value should be extracted and set to this parameter. clientSecret(OPTIONAL)-
The client secret extracted from
Authorizationheader of the token request from the client application.If the token endpoint of the service implementation supports Basic Authentication as a means of client authentication, and the request from the client application contained its client secret in
Authorizationheader, the value should be extracted and set to this parameter. clientCertificate(OPTIONAL)-
The client certificate from the MTLS of the token request from the client application. See RFC 8705 (OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound Access Tokens) for details.
clientCertificatePath(OPTIONAL)-
The certificate path presented by the client during client authentication. The certificates are strings in PEM format.
properties(OPTIONAL)-
Extra properties to associate with an access token. Note that
propertiesparameter is accepted only when Content-Type of the request is application/json, so don't use application/x-www-form-urlencoded if you want to specifyproperties. dpop(OPTIONAL)-
The value of the
DPoPHTTP header. See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details. htm(OPTIONAL)-
The HTTP method of the token request. In normal cases, the value should be
"POST". If omitted,"POST"is used as the default value. See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details. htu(OPTIONAL)-
The URL of the token endpoint. If omitted, the
tokenEndpointproperty ofServiceis used as the default value. See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details. jwtAtClaims(OPTIONAL; Authlete 2.3 onwards)-
Additional claims in JSON object format that are added to the payload part of the JWT access token. See the description of
getJwtAtClaims()for details. accessToken(OPTIONAL)-
The representation of an access token that may be issued as a result of the Authlete API call. See
getAccessToken()for details. accessTokenDuration(OPTIONAL)-
The duration of the access token that may be issued as a result of the Authlete API call. See
getAccessTokenDuration()for details. refreshTokenDuration(OPTIONAL)-
The duration of the refresh token that may be issued as a result of the Authlete API call. See
getRefreshTokenDuration()for details. dpopNonceRequired(OPTIONAL; Authlete 3.0 onwards)-
The flag indicating whether to require the DPoP proof JWT to include the
nonceclaim. Even if the service'sdpopNonceRequiredproperty is false, calling the/auth/tokenAPI with thisdpopNonceRequiredparameter true will force the Authlete API to check whether the DPoP proof JWT includes the expected nonce value. oauthClientAttestation(OPTIONAL; Authlete 3.0 onwards)-
The value of the
OAuth-Client-AttestationHTTP header, which is defined in the specification of OAuth 2.0 Attestation-Based Client Authentication. oauthClientAttestationPop(OPTIONAL; Authlete 3.0 onwards)-
The value of the
OAuth-Client-Attestation-PoPHTTP header, which is defined in the specification of OAuth 2.0 Attestation-Based Client Authentication.
An entity body of a token request may contain the client ID (
client_id) and the client secret (client_secret) along with other request parameters as described in RFC 6749, 2.3.1. Client Password. If the client credentials are contained in bothAuthorizationheader and the entity body, they must be identical. Otherwise, Authlete's/auth/tokenAPI generates an error (it's not a service error but a client error).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TokenRequest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAccessToken()Get the representation of an access token that may be issued as a result of the Authlete API call.longgetAccessTokenDuration()Get the duration of the access token that may be issued as a result of the Authlete API call.StringgetClientCertificate()Get the client certificate from the MTLS of the token request from the client application.String[]getClientCertificatePath()Get the certificate path presented by the client during client authentication.StringgetClientId()Get the client ID extracted fromAuthorizationheader of the token request from the client application.StringgetClientSecret()Get the client secret extracted fromAuthorizationheader of the token request from the client application.StringgetDpop()Get theDPoPheader presented by the client during the request to the token endpoint.StringgetHtm()Get the HTTP method of the token request.StringgetHtu()Get the URL of the token endpoint.StringgetJwtAtClaims()Get the additional claims in JSON object format that are added to the payload part of the JWT access token.StringgetOauthClientAttestation()Get the value of theOAuth-Client-AttestationHTTP header.StringgetOauthClientAttestationPop()Get the value of theOAuth-Client-Attestation-PoPHTTP header.StringgetParameters()Get the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.Property[]getProperties()Get the extra properties to associate with an access token which may be issued by this request.longgetRefreshTokenDuration()Get the duration of the refresh token that may be issued as a result of the Authlete API call.booleanisDpopNonceRequired()Get the flag indicating whether to check if the DPoP proof JWT includes the expectednoncevalue.TokenRequestsetAccessToken(String accessToken)Set the representation of an access token that may be issued as a result of the Authlete API call.TokenRequestsetAccessTokenDuration(long duration)Set the duration of the access token that may be issued as a result of the Authlete API call.TokenRequestsetClientCertificate(String clientCertificate)Set the client certificate from the MTLS of the token request from the client application.TokenRequestsetClientCertificatePath(String[] clientCertificatePath)Set the certificate path presented by the client during client authentication.TokenRequestsetClientId(String clientId)Set the client ID extracted fromAuthorizationheader of the token request from the client application.TokenRequestsetClientSecret(String clientSecret)Set the client secret extracted fromAuthorizationheader of the token request from the client application.TokenRequestsetDpop(String dpop)Set theDPoPheader presented by the client during the request to the token endpoint.TokenRequestsetDpopNonceRequired(boolean required)Set the flag indicating whether to check if the DPoP proof JWT includes the expectednoncevalue.TokenRequestsetHtm(String htm)Set the HTTP method of the token request.TokenRequestsetHtu(String htu)Set the URL of the token endpoint.TokenRequestsetJwtAtClaims(String claims)Set the additional claims in JSON object format that are added to the payload part of the JWT access token.TokenRequestsetOauthClientAttestation(String jwt)Set the value of theOAuth-Client-AttestationHTTP header.TokenRequestsetOauthClientAttestationPop(String jwt)Set the value of theOAuth-Client-Attestation-PoPHTTP header.TokenRequestsetParameters(String parameters)Set the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.TokenRequestsetParameters(Map<String,String[]> parameters)Set the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.TokenRequestsetProperties(Property[] properties)Set extra properties to associate with an access token which may be issued by this request.TokenRequestsetRefreshTokenDuration(long duration)Set the duration of the refresh token that may be issued as a result of the Authlete API call.
-
-
-
Method Detail
-
getParameters
public String getParameters()
Get the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.
-
setParameters
public TokenRequest setParameters(String parameters)
Set the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.
-
setParameters
public TokenRequest setParameters(Map<String,String[]> parameters)
Set the value ofparameterswhich are the request parameters that the OAuth 2.0 token endpoint of the service implementation received from the client application.This method converts the given map into a string in
x-www-form-urlencodedand passes it tosetParameters(String)method.- Parameters:
parameters- Request parameters.- Returns:
thisobject.- Since:
- 1.24
-
getClientId
public String getClientId()
Get the client ID extracted fromAuthorizationheader of the token request from the client application.
-
setClientId
public TokenRequest setClientId(String clientId)
Set the client ID extracted fromAuthorizationheader of the token request from the client application.
-
getClientSecret
public String getClientSecret()
Get the client secret extracted fromAuthorizationheader of the token request from the client application.
-
setClientSecret
public TokenRequest setClientSecret(String clientSecret)
Set the client secret extracted fromAuthorizationheader of the token request from the client application.
-
getClientCertificate
public String getClientCertificate()
Get the client certificate from the MTLS of the token request from the client application.- Since:
- 2.12
-
setClientCertificate
public TokenRequest setClientCertificate(String clientCertificate)
Set the client certificate from the MTLS of the token request from the client application.- Since:
- 2.12
-
getProperties
public Property[] getProperties()
Get the extra properties to associate with an access token which may be issued by this request.- Returns:
- Extra properties.
- Since:
- 1.30
-
setProperties
public TokenRequest setProperties(Property[] properties)
Set extra properties to associate with an access token which may be issued by this request.If the value of
grant_typeparameter contained in the token request from the client application isauthorization_code, properties set by this method will be added as the extra properties of a newly created access token. The extra properties specified when the authorization code was issued (usingAuthorizationIssueRequest.setProperties(Property[])) will also be used, but their values will be overwritten if the extra properties set by this method have the same keys. In other words, extra properties contained in this request will be merged into existing extra properties which are associated with the authorization code.Otherwise, if the value of
grant_typeparameter contained in the token request from the client application isrefresh_token, properties set by this method will be added to the existing extra properties of the corresponding access token. Extra properties having the same keys will be overwritten in the same manner as the case ofgrant_type=authorization_code.Otherwise, if the value of
grant_typeparameter contained in the token request from the client application isclient_credentials, properties set by this method will be used simply as extra properties of a newly created access token. Because Client Credentials flow does not have a preceding authorization request, merging extra properties will not be performed. This is different from the cases ofgrant_type=authorization_codeandgrant_type=refresh_token.In other cases (
grant_type=password), properties set by this method will not be used. When you want to associate extra properties with an access token which is issued using Resource Owner Password Credentials flow, useTokenIssueRequest.setProperties(Property[])method instead.The argument
propertiesis an array of properties. Each property must be a pair of a string key and a string value. That is, each property must be a string array of size 2. The key must not benullor an empty string, but the value may be.Keys of extra properties will be used as labels of top-level entries in a JSON response containing an access token which is returned from an authorization server. An example is
example_parameter, which you can find in 5.1. Successful Response in RFC 6749. The following code snippet is an example to set one extra property havingexample_parameteras its key andexample_valueas its value.Property[] properties = { newProperty("example_parameter", "example_value") }; request.setProperties(properties);Keys listed below should not be used and they would be ignored on the server side even if they were used. It's because they are reserved in RFC 6749 and OpenID Connect Core 1.0.
access_tokentoken_typeexpires_inrefresh_tokenscopeerrorerror_descriptionerror_uriid_token
Note that there is an upper limit on the total size of extra properties. On the server side, the properties will be (1) converted to a multidimensional string array, (2) converted to JSON, (3) encrypted by AES/CBC/PKCS5Padding, (4) encoded by base64url, and then stored into the database. The length of the resultant string must not exceed 65,535 in bytes. This is the upper limit, but we think it is big enough.
- Parameters:
properties- Extra properties.- Returns:
thisobject.- Since:
- 1.30
-
getClientCertificatePath
public String[] getClientCertificatePath()
Get the certificate path presented by the client during client authentication. These certificates are strings in PEM format.- Returns:
- The client certificate path as an array of strings in PEM format.
- Since:
- 2.15
-
setClientCertificatePath
public TokenRequest setClientCertificatePath(String[] clientCertificatePath)
Set the certificate path presented by the client during client authentication. These certificates are strings in PEM format.- Parameters:
clientCertificatePath- The client certificate path as an array of strings in PEM format.- Returns:
thisobject.- Since:
- 2.15
-
getDpop
public String getDpop()
Get theDPoPheader presented by the client during the request to the token endpoint. The header contains a signed JWT which includes the public key that is paired with the private key used to sign the JWT.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Returns:
- The
DPoPheader string. - Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
setDpop
public TokenRequest setDpop(String dpop)
Set theDPoPheader presented by the client during the request to the token endpoint. The header contains a signed JWT which includes the public key that is paired with the private key used to sign the JWT.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Parameters:
dpop- TheDPoPheader string.- Returns:
thisobject.- Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
getHtm
public String getHtm()
Get the HTTP method of the token request. This field is used to validate theDPoPheader.In normal cases, the value is
"POST". When this parameter is omitted,"POST"is used as the default value.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Returns:
- The HTTP method as a string. For example,
"POST". - Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
setHtm
public TokenRequest setHtm(String htm)
Set the HTTP method of the token request. This field is used to validate theDPoPheader.In normal cases, the value is
"POST". When this parameter is omitted,"POST"is used as the default value.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Parameters:
htm- The HTTP method as a string. For example,"POST".- Returns:
thisobject.- Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
getHtu
public String getHtu()
Get the URL of the token endpoint. This field is used to validate theDPoPheader.If this parameter is omitted, the
tokenEndpointproperty of theServiceis used as the default value.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Returns:
- The URL of the token endpoint.
- Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
setHtu
public TokenRequest setHtu(String htu)
Set the URL of the token endpoint. This field is used to validate theDPoPheader.If this parameter is omitted, the
tokenEndpointproperty of theServiceis used as the default value.See RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP) for details.
- Parameters:
htu- The URL of the token endpoint.- Returns:
thisobject.- Since:
- 2.70
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
getJwtAtClaims
public String getJwtAtClaims()
Get the additional claims in JSON object format that are added to the payload part of the JWT access token.This request parameter has a meaning only when the format of access tokens issued by this service is JWT. In other words, it has a meaning only when the
accessTokenSignAlgproperty of theServiceholds a non-null value. See the description of thegetAccessTokenSignAlg()method for details.Note that this
jwtAtClaimsrequest parameter to the/auth/tokenAPI works only in the client credentials flow (RFC 6749 Section 4.4). For other flows, additional claims need to be passed to Authlete through other APIs. For example, to embed additional claims in an access token that is issued by the authorization code flow (RFC 6749 Section 4.1), thejwtAtClaimsrequest parameter of the/auth/authorization/issueAPI has to be used.- Returns:
- Additional claims that are added to the payload part of the JWT access token.
- Since:
- 3.35, Authlete 2.3
-
setJwtAtClaims
public TokenRequest setJwtAtClaims(String claims)
Set the additional claims in JSON object format that are added to the payload part of the JWT access token.This request parameter has a meaning only when the format of access tokens issued by this service is JWT. In other words, it has a meaning only when the
accessTokenSignAlgproperty of theServiceholds a non-null value. See the description of thegetAccessTokenSignAlg()method for details.Note that this
jwtAtClaimsrequest parameter to the/auth/tokenAPI works only in the client credentials flow (RFC 6749 Section 4.4). For other flows, additional claims need to be passed to Authlete through other APIs. For example, to embed additional claims in an access token that is issued by the authorization code flow (RFC 6749 Section 4.1), thejwtAtClaimsrequest parameter of the/auth/authorization/issueAPI has to be used.- Parameters:
claims- Additional claims that are added to the payload part of the JWT access token.- Returns:
thisobject.- Since:
- 3.35, Authlete 2.3
-
getAccessToken
public String getAccessToken()
Get the representation of an access token that may be issued as a result of the Authlete API call.Basically, it is the Authlete server's role to generate an access token. However, some systems may have inflexible restrictions on the format of access tokens. Such systems may use this
accessTokenrequest parameter to specify the representation of an access token by themselves instead of leaving the access token generation task to the Authlete server.Usually, the Authlete server (1) generates a random 256-bit value, (2) base64url-encodes the value into a 43-character string, and (3) uses the resultant string as the representation of an access token. The Authlete implementation is written on the assumption that the 256-bit entropy is big enough. Therefore, make sure that the entropy of the value of the
The entropy does not necessarily have to be equal to or greater than 256 bits. For example, 192-bit random values (which will become 32-character strings when encoded by base64url) may be enough. However, note that if the entropy is too low, access token string values will collide and Authlete API calls will fail.accessTokenrequest parameter is big enough, too.When no access token is generated as a result of the Authlete API call, this
accessTokenrequest parameter is not used.- Returns:
- The representation of an access token that may be issued as a result of the Authlete API call.
- Since:
- 3.24, Authlete 2.2.27
-
setAccessToken
public TokenRequest setAccessToken(String accessToken)
Set the representation of an access token that may be issued as a result of the Authlete API call.Basically, it is the Authlete server's role to generate an access token. However, some systems may have inflexible restrictions on the format of access tokens. Such systems may use this
accessTokenrequest parameter to specify the representation of an access token by themselves instead of leaving the access token generation task to the Authlete server.Usually, the Authlete server (1) generates a random 256-bit value, (2) base64url-encodes the value into a 43-character string, and (3) uses the resultant string as the representation of an access token. The Authlete implementation is written on the assumption that the 256-bit entropy is big enough. Therefore, make sure that the entropy of the value of the
The entropy does not necessarily have to be equal to or greater than 256 bits. For example, 192-bit random values (which will become 32-character strings when encoded by base64url) may be enough. However, note that if the entropy is too low, access token string values will collide and Authlete API calls will fail.accessTokenrequest parameter is big enough, too.When no access token is generated as a result of the Authlete API call, this
accessTokenrequest parameter is not used.- Parameters:
accessToken- The representation of an access token that may be issued as a result of the Authlete API call.- Returns:
thisobject.- Since:
- 3.24, Authlete 2.2.27
-
getAccessTokenDuration
public long getAccessTokenDuration()
Get the duration of the access token that may be issued as a result of the Authlete API call.When this request parameter holds a positive integer, it is used as the duration of the access token. In other cases, this request parameter is ignored.
- Returns:
- The duration of the access token in seconds.
- Since:
- 3.64, Authlete 2.2.41, Authlete 2.3.5, Authlete 3.0
-
setAccessTokenDuration
public TokenRequest setAccessTokenDuration(long duration)
Set the duration of the access token that may be issued as a result of the Authlete API call.When this request parameter holds a positive integer, it is used as the duration of the access token. In other cases, this request parameter is ignored.
- Parameters:
duration- The duration of the access token in seconds.- Returns:
thisrequest parameter.- Since:
- 3.64, Authlete 2.2.41, Authlete 2.3.5, Authlete 3.0
-
getRefreshTokenDuration
public long getRefreshTokenDuration()
Get the duration of the refresh token that may be issued as a result of the Authlete API call.When this request parameter holds a positive integer, it is used as the duration of the refresh token. In other cases, this request parameter is ignored.
- Returns:
- The duration of the refresh token in seconds.
- Since:
- 4.8, Authlete 2.3.20, Authlete 3.0
-
setRefreshTokenDuration
public TokenRequest setRefreshTokenDuration(long duration)
Set the duration of the refresh token that may be issued as a result of the Authlete API call.When this request parameter holds a positive integer, it is used as the duration of the refresh token. In other cases, this request parameter is ignored.
- Parameters:
duration- The duration of the refresh token in seconds.- Returns:
thisobject.- Since:
- 4.8, Authlete 2.3.20, Authlete 3.0
-
isDpopNonceRequired
public boolean isDpopNonceRequired()
Get the flag indicating whether to check if the DPoP proof JWT includes the expectednoncevalue.If this request parameter is
trueor if the service'sdpopNonceRequiredproperty (Service.isDpopNonceRequired()) istrue, the/auth/tokenAPI checks if the DPoP proof JWT includes the expectednoncevalue. In this case, the response from the/auth/tokenAPI will include thedpopNonceresponse parameter, which should be used as the value of theDPoP-NonceHTTP header.- Returns:
trueif the/auth/tokenAPI checks whether the DPoP proof JWT includes the expectednoncevalue, even if the service'sdpopNonceRequiredproperty is false.- Since:
- 3.82, Authlete 3.0
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
setDpopNonceRequired
public TokenRequest setDpopNonceRequired(boolean required)
Set the flag indicating whether to check if the DPoP proof JWT includes the expectednoncevalue.If this request parameter is
trueor if the service'sdpopNonceRequiredproperty (Service.isDpopNonceRequired()) istrue, the/auth/tokenAPI checks if the DPoP proof JWT includes the expectednoncevalue. In this case, the response from the/auth/tokenAPI will include thedpopNonceresponse parameter, which should be used as the value of theDPoP-NonceHTTP header.- Parameters:
required-trueto have the/auth/tokenAPI check whether the DPoP proof JWT includes the expectednoncevalue, even if the service'sdpopNonceRequiredproperty is false.- Returns:
thisobject.- Since:
- 3.82, Authlete 3.0
- See Also:
- RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPoP)
-
getOauthClientAttestation
public String getOauthClientAttestation()
Get the value of theOAuth-Client-AttestationHTTP header.- Returns:
- The value of the
OAuth-Client-AttestationHTTP header. - Since:
- 4.3, Authlete 3.0
- See Also:
- OAuth 2.0 Attestation-Based Client Authentication
-
setOauthClientAttestation
public TokenRequest setOauthClientAttestation(String jwt)
Set the value of theOAuth-Client-AttestationHTTP header.- Parameters:
jwt- The value of theOAuth-Client-AttestationHTTP header.- Returns:
thisobject.- Since:
- 4.3, Authlete 3.0
- See Also:
- OAuth 2.0 Attestation-Based Client Authentication
-
getOauthClientAttestationPop
public String getOauthClientAttestationPop()
Get the value of theOAuth-Client-Attestation-PoPHTTP header.- Returns:
- The value of the
OAuth-Client-Attestation-PoPHTTP header. - Since:
- 4.3, Authlete 3.0
- See Also:
- OAuth 2.0 Attestation-Based Client Authentication
-
setOauthClientAttestationPop
public TokenRequest setOauthClientAttestationPop(String jwt)
Set the value of theOAuth-Client-Attestation-PoPHTTP header.- Parameters:
jwt- The value of theOAuth-Client-Attestation-PoPHTTP header.- Returns:
thisobject.- Since:
- 4.3, Authlete 3.0
- See Also:
- OAuth 2.0 Attestation-Based Client Authentication
-
-