Class TokenRequest
- java.lang.Object
-
- net.openid.appauth.TokenRequest
-
public class TokenRequest extends Object
An OAuth2 token request.These are used to exchange codes for tokens, or exchange a refresh token for updated tokens.
- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.1.3 https://tools.ietf.org/html/rfc6749#section-4.1.3”
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TokenRequest.Builder
Creates instances ofTokenRequest
.
-
Field Summary
Fields Modifier and Type Field Description Map<String,String>
additionalParameters
Additional parameters to be passed as part of the request.String
authorizationCode
An authorization code to be exchanged for one or more tokens.String
clientId
The client identifier.String
codeVerifier
The code verifier that was used to generate the challenge in the original authorization request, if one was used.AuthorizationServiceConfiguration
configuration
The service’sconfiguration
.static String
GRANT_TYPE_CLIENT_CREDENTIALS
The grant type used when requesting an access token using client credentials, typically TLS client certificates.static String
GRANT_TYPE_PASSWORD
The grant type used when requesting an access token using a username and password.String
grantType
The type of token being sent to the token endpoint.String
nonce
The (optional) nonce associated with the current session.static String
PARAM_CLIENT_ID
Uri
redirectUri
The client’s redirect URI.String
refreshToken
A refresh token to be exchanged for a new token.String
scope
A space-delimited set of scopes used to determine the scope of any returned tokens.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,String>
getRequestParameters()
Produces the set of request parameters for this query, which can be further processed into a request body.Set<String>
getScopeSet()
Derives the set of scopes from the consolidated, space-delimited scopes in thescope
field.static TokenRequest
jsonDeserialize(String json)
Reads a token request from a JSON string representation produced byjsonSerializeString()
.static TokenRequest
jsonDeserialize(JSONObject json)
Reads a token request from a JSON string representation produced byjsonSerialize()
.JSONObject
jsonSerialize()
Produces a JSON string representation of the token request for persistent storage or local transmission (e.g.String
jsonSerializeString()
Produces a JSON string representation of the token request for persistent storage or local transmission (e.g.
-
-
-
Field Detail
-
PARAM_CLIENT_ID
public static final String PARAM_CLIENT_ID
- See Also:
- Constant Field Values
-
GRANT_TYPE_PASSWORD
public static final String GRANT_TYPE_PASSWORD
The grant type used when requesting an access token using a username and password.This grant type is not directly supported by this library.
- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.3.2 https://tools.ietf.org/html/rfc6749#section-4.3.2”
, Constant Field Values
-
GRANT_TYPE_CLIENT_CREDENTIALS
public static final String GRANT_TYPE_CLIENT_CREDENTIALS
The grant type used when requesting an access token using client credentials, typically TLS client certificates.This grant type is not directly supported by this library.
- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.4.2 https://tools.ietf.org/html/rfc6749#section-4.4.2”
, Constant Field Values
-
configuration
@NonNull public final AuthorizationServiceConfiguration configuration
The service’sconfiguration
.This configuration specifies how to connect to a particular OAuth provider. Configurations may be
created manually
, orvia an OpenID Connect Discovery Document
.
-
clientId
@NonNull public final String clientId
The client identifier.- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4 https://tools.ietf.org/html/rfc6749#section-4”
,“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.1.1 https://tools.ietf.org/html/rfc6749#section-4.1.1”
-
grantType
@NonNull public final String grantType
The type of token being sent to the token endpoint.- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.1.3 https://tools.ietf.org/html/rfc6749#section-4.1.3”
-
redirectUri
@Nullable public final Uri redirectUri
The client’s redirect URI.Required if this token request is to exchange an authorization code for one or more tokens, and must be identical to the value specified in the original authorization request.
- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 3.1.2 https://tools.ietf.org/html/rfc6749#section-3.1.2”
,“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.1.3 https://tools.ietf.org/html/rfc6749#section-4.1.3”
-
authorizationCode
@Nullable public final String authorizationCode
An authorization code to be exchanged for one or more tokens.- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 4.1.3 https://tools.ietf.org/html/rfc6749#section-4.1.3”
-
scope
@Nullable public final String scope
A space-delimited set of scopes used to determine the scope of any returned tokens.- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 3.3 https://tools.ietf.org/html/rfc6749#section-3.3”
,“The OAuth 2.0 Authorization Framework (RFC 6749), Section 6 https://tools.ietf.org/html/rfc6749#section-6”
-
refreshToken
@Nullable public final String refreshToken
A refresh token to be exchanged for a new token.- See Also:
“The OAuth 2.0 Authorization Framework (RFC 6749), Section 6 https://tools.ietf.org/html/rfc6749#section-6”
-
codeVerifier
@Nullable public final String codeVerifier
The code verifier that was used to generate the challenge in the original authorization request, if one was used.- See Also:
“Proof Key for Code Exchange by OAuth Public Clients (RFC 7636), Section 4 https://tools.ietf.org/html/rfc7636#section-4”
-
additionalParameters
@NonNull public final Map<String,String> additionalParameters
Additional parameters to be passed as part of the request.
-
-
Method Detail
-
getScopeSet
@Nullable public Set<String> getScopeSet()
Derives the set of scopes from the consolidated, space-delimited scopes in thescope
field.If no scopes were specified for this request, the method will return
null
.
-
getRequestParameters
@NonNull public Map<String,String> getRequestParameters()
Produces the set of request parameters for this query, which can be further processed into a request body.
-
jsonSerialize
@NonNull public JSONObject jsonSerialize()
Produces a JSON string representation of the token request for persistent storage or local transmission (e.g.between activities).
-
jsonSerializeString
@NonNull public String jsonSerializeString()
Produces a JSON string representation of the token request for persistent storage or local transmission (e.g.between activities). This method is just a convenience wrapper for
jsonSerialize()
, converting the JSON object to its string form.
-
jsonDeserialize
@NonNull public static TokenRequest jsonDeserialize(JSONObject json) throws JSONException
Reads a token request from a JSON string representation produced byjsonSerialize()
.- Throws:
JSONException
- if the provided JSON does not match the expected structure.
-
jsonDeserialize
@NonNull public static TokenRequest jsonDeserialize(@NonNull String json) throws JSONException
Reads a token request from a JSON string representation produced byjsonSerializeString()
.This method is just a convenience wrapper for
jsonDeserialize(JSONObject)
, converting the JSON string to its JSON object form.- Throws:
JSONException
- if the provided JSON does not match the expected structure.
-
-