Package com.nimbusds.oauth2.sdk.token
Class AccessToken
java.lang.Object
com.nimbusds.oauth2.sdk.id.Identifier
com.nimbusds.oauth2.sdk.token.Token
com.nimbusds.oauth2.sdk.token.AccessToken
- All Implemented Interfaces:
Serializable,Comparable<Identifier>,net.minidev.json.JSONAware
- Direct Known Subclasses:
BearerAccessToken,DPoPAccessToken,NAAccessToken,TypelessAccessToken
The base abstract class for access tokens. Concrete extending classes should
be immutable.
Related specifications:
- OAuth 2.0 (RFC 6749), sections 1.4 and 5.1.
- OAuth 2.0 Rich Authorization Requests (RFC 9396), section 7.
- OAuth 2.0 Token Exchange (RFC 8693), section 3.
- See Also:
-
Field Summary
Fields inherited from class com.nimbusds.oauth2.sdk.id.Identifier
DEFAULT_BYTE_LENGTH, secureRandom -
Constructor Summary
ConstructorsConstructorDescriptionAccessToken(AccessTokenType type) Creates a new minimal access token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded.AccessToken(AccessTokenType type, int byteLength) Creates a new minimal access token with a randomly generated value of the specified byte length, Base64URL-encoded.AccessToken(AccessTokenType type, int byteLength, long lifetime, Scope scope) Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded.AccessToken(AccessTokenType type, int byteLength, long lifetime, Scope scope, TokenTypeURI issuedTokenType) Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded.AccessToken(AccessTokenType type, int byteLength, long lifetime, Scope scope, List<AuthorizationDetail> authorizationDetails, TokenTypeURI issuedTokenType) Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded.AccessToken(AccessTokenType type, long lifetime, Scope scope) Creates a new access token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded.AccessToken(AccessTokenType type, String value) Creates a new minimal access token with the specified value.AccessToken(AccessTokenType type, String value, long lifetime, Scope scope) Creates a new access token with the specified value.AccessToken(AccessTokenType type, String value, long lifetime, Scope scope, TokenTypeURI issuedTokenType) Creates a new access token with the specified value.AccessToken(AccessTokenType type, String value, long lifetime, Scope scope, List<AuthorizationDetail> authorizationDetails, TokenTypeURI issuedTokenType) Creates a new access token with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionReturns the authorisation details for this access token.Returns the identifier URI for the type of this access token.longReturns the lifetime of this access token.Returns the token parameter names included in the JSON object, as required for the composition of an access token response.getScope()Returns the scope of this access token.getType()Returns the access token type.static AccessTokenparse(HTTPRequest request) Parses an HTTP request header value for an access token.static AccessTokenDeprecated.static AccessTokenparse(String header, AccessTokenType preferredType) Parses anAuthorizationHTTP request header value for an access token.static AccessTokenparse(net.minidev.json.JSONObject jsonObject) Parses an access token from a JSON object access token response.abstract StringReturns theAuthorizationHTTP request header value for this access token.net.minidev.json.JSONObjectReturns the token parameters as a JSON object, as required for the composition of an access token response.Returns the JSON string representation of this identifier.Methods inherited from class com.nimbusds.oauth2.sdk.token.Token
getCustomParametersMethods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
compareTo, equals, getValue, hashCode, toString, toStringList
-
Constructor Details
-
AccessToken
Creates a new minimal access token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded. The optional lifetime, scope and token type URI are left unspecified.- Parameters:
type- The access token type. Must not benull.
-
AccessToken
Creates a new minimal access token with a randomly generated value of the specified byte length, Base64URL-encoded. The optional lifetime, scope and token type URI are left unspecified.- Parameters:
type- The access token type. Must not benull.byteLength- The byte length of the value to generate. Must be greater than one.
-
AccessToken
Creates a new access token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded. The optional token type URI is left unspecified.- Parameters:
type- The access token type. Must not benull.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.
-
AccessToken
Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded. The optional token type URI is left unspecified.- Parameters:
type- The access token type. Must not benull.byteLength- The byte length of the value to generate. Must be greater than one.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.
-
AccessToken
public AccessToken(AccessTokenType type, int byteLength, long lifetime, Scope scope, TokenTypeURI issuedTokenType) Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded.- Parameters:
type- The access token type. Must not benull.byteLength- The byte length of the value to generate. Must be greater than one.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.issuedTokenType- The token type URI,nullif not specified.
-
AccessToken
public AccessToken(AccessTokenType type, int byteLength, long lifetime, Scope scope, List<AuthorizationDetail> authorizationDetails, TokenTypeURI issuedTokenType) Creates a new access token with a randomly generated value of the specified byte length, Base64URL-encoded.- Parameters:
type- The access token type. Must not benull.byteLength- The byte length of the value to generate. Must be greater than one.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.authorizationDetails- The authorisation details,nullif not specified.issuedTokenType- The token type URI,nullif not specified.
-
AccessToken
Creates a new minimal access token with the specified value. The optional lifetime, scope and token type URI are left unspecified.- Parameters:
type- The access token type. Must not benull.value- The access token value. Must not benullor empty string.
-
AccessToken
Creates a new access token with the specified value. The optional token type URI is left unspecified.- Parameters:
type- The access token type. Must not benull.value- The access token value. Must not benullor empty string.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.
-
AccessToken
public AccessToken(AccessTokenType type, String value, long lifetime, Scope scope, TokenTypeURI issuedTokenType) Creates a new access token with the specified value.- Parameters:
type- The access token type. Must not benull.value- The access token value. Must not benullor empty string.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.issuedTokenType- The token type URI,nullif not specified.
-
AccessToken
public AccessToken(AccessTokenType type, String value, long lifetime, Scope scope, List<AuthorizationDetail> authorizationDetails, TokenTypeURI issuedTokenType) Creates a new access token with the specified value.- Parameters:
type- The access token type. Must not benull.value- The access token value. Must not benullor empty string.lifetime- The lifetime in seconds, 0 if not specified.scope- The scope,nullif not specified.authorizationDetails- The authorisation details,nullif not specified.issuedTokenType- The token type URI,nullif not specified.
-
-
Method Details
-
getType
Returns the access token type.- Returns:
- The access token type.
-
getLifetime
Returns the lifetime of this access token.- Returns:
- The lifetime in seconds, 0 if not specified.
-
getScope
Returns the scope of this access token.- Returns:
- The scope,
nullif not specified.
-
getAuthorizationDetails
Returns the authorisation details for this access token.- Returns:
- The authorisation details,
nullif not specified.
-
getIssuedTokenType
Returns the identifier URI for the type of this access token. Used in OAuth 2.0 Token Exchange (RFC 8693).- Returns:
- The token type URI,
nullif not specified.
-
getParameterNames
Description copied from class:TokenReturns the token parameter names included in the JSON object, as required for the composition of an access token response. See OAuth 2.0 (RFC 6749), section 5.1.- Specified by:
getParameterNamesin classToken- Returns:
- The token parameter names.
-
toJSONObject
Description copied from class:TokenReturns the token parameters as a JSON object, as required for the composition of an access token response. See OAuth 2.0 (RFC 6749), section 5.1.Note that JSONObject implements Map<String,Object>.
Example:
{ "access_token" : "2YotnFZFEjr1zCsicMWpAA", "token_type" : "example", "expires_in" : 3600, "example_parameter" : "example_value" }- Specified by:
toJSONObjectin classToken- Returns:
- The token parameters as a JSON object.
-
toJSONString
Description copied from class:IdentifierReturns the JSON string representation of this identifier.- Specified by:
toJSONStringin interfacenet.minidev.json.JSONAware- Overrides:
toJSONStringin classIdentifier- Returns:
- The JSON string.
-
toAuthorizationHeader
Returns theAuthorizationHTTP request header value for this access token.- Returns:
- The
Authorizationheader value.
-
parse
Parses an access token from a JSON object access token response. Only bearer and DPoP access tokens are supported.- Parameters:
jsonObject- The JSON object to parse. Must not benull.- Returns:
- The access token.
- Throws:
ParseException- If the JSON object couldn't be parsed to an access token.
-
parse
Deprecated.Parses anAuthorizationHTTP request header value for an access token. Only bearer access token are supported.- Parameters:
header- TheAuthorizationheader value to parse. Must not benull.- Returns:
- The access token.
- Throws:
ParseException- If theAuthorizationheader value couldn't be parsed to an access token.- See Also:
-
parse
Parses anAuthorizationHTTP request header value for an access token. Only bearer and DPoP access token are supported.- Parameters:
header- TheAuthorizationheader value to parse. Must not benull.preferredType- The preferred (primary) access token type. Must be eitherAccessTokenType.BEARERorAccessTokenType.DPOPand notnull.- Returns:
- The access token.
- Throws:
ParseException- If theAuthorizationheader value couldn't be parsed to an access token.
-
parse
Parses an HTTP request header value for an access token.- Parameters:
request- The HTTP request to parse. Must not benull.- Returns:
- The access token.
- Throws:
ParseException- If an access token wasn't found in the HTTP request.
-