@Immutable public final class BearerAccessToken extends AccessToken
Example bearer access token serialised to JSON:
{ "access_token" : "2YotnFZFEjr1zCsicMWpAA", "token_type" : "bearer", "expires_in" : 3600, "scope" : "read write" }
The above example token serialised to a HTTP Authorization header:
Authorization: Bearer 2YotnFZFEjr1zCsicMWpAA
Related specifications:
DEFAULT_BYTE_LENGTH
Constructor and Description |
---|
BearerAccessToken()
Creates a new minimal bearer access token with a randomly generated
256-bit (32-byte) value, Base64URL-encoded.
|
BearerAccessToken(int byteLength)
Creates a new minimal bearer access token with a randomly generated
value of the specified byte length, Base64URL-encoded.
|
BearerAccessToken(int byteLength,
long lifetime,
Scope scope)
Creates a new bearer access token with a randomly generated value of
the specified byte length, Base64URL-encoded.
|
BearerAccessToken(long lifetime,
Scope scope)
Creates a new bearer access token with a randomly generated 256-bit
(32-byte) value, Base64URL-encoded.
|
BearerAccessToken(String value)
Creates a new minimal bearer access token with the specified value.
|
BearerAccessToken(String value,
long lifetime,
Scope scope)
Creates a new bearer access token with the specified value and
optional lifetime and scope.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Overrides
Object.equals() . |
static BearerAccessToken |
parse(HTTPRequest request)
Parses an HTTP request for a bearer access token.
|
static BearerAccessToken |
parse(net.minidev.json.JSONObject jsonObject)
Parses a bearer access token from a JSON object access token
response.
|
static BearerAccessToken |
parse(String header)
Parses an HTTP Authorization header for a bearer access token.
|
String |
toAuthorizationHeader()
Returns the HTTP Authorization header value for this bearer access
token.
|
getLifetime, getScope, getType, toJSONObject, toJSONString
compareTo, getValue, hashCode, toString
public BearerAccessToken()
public BearerAccessToken(int byteLength)
byteLength
- The byte length of the value to generate. Must be
greater than one.public BearerAccessToken(long lifetime, Scope scope)
lifetime
- The lifetime in seconds, 0 if not specified.scope
- The scope, null
if not specified.public BearerAccessToken(int byteLength, long lifetime, Scope scope)
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, null
if not specified.public BearerAccessToken(String value)
value
- The access token value. Must not be null
or
empty string.public BearerAccessToken(String value, long lifetime, Scope scope)
value
- The access token value. Must not be null
or
empty string.lifetime
- The lifetime in seconds, 0 if not specified.scope
- The scope, null
if not specified.public String toAuthorizationHeader()
Example:
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9
toAuthorizationHeader
in class AccessToken
public boolean equals(Object object)
Identifier
Object.equals()
.equals
in class Identifier
object
- The object to compare to.true
if the objects have the same value, otherwise
false
.public static BearerAccessToken parse(net.minidev.json.JSONObject jsonObject) throws ParseException
jsonObject
- The JSON object to parse. Must not be
null
.ParseException
- If the JSON object couldn't be parsed to a
bearer access token.public static BearerAccessToken parse(String header) throws ParseException
header
- The HTTP Authorization header value to parse. May be
null
if the header is missing, in which case
an exception will be thrown.ParseException
- If the HTTP Authorization header value
couldn't be parsed to a bearer access token.public static BearerAccessToken parse(HTTPRequest request) throws ParseException
request
- The HTTP request to parse. Must not be null
.ParseException
- If a bearer access token wasn't found in the
HTTP request.Copyright © 2014 Connect2id Ltd.. All Rights Reserved.