com.nimbusds.oauth2.sdk.token
Class BearerAccessToken

java.lang.Object
  extended by com.nimbusds.oauth2.sdk.id.Identifier
      extended by com.nimbusds.oauth2.sdk.token.Token
          extended by com.nimbusds.oauth2.sdk.token.AccessToken
              extended by com.nimbusds.oauth2.sdk.token.BearerAccessToken
All Implemented Interfaces:
Comparable<AccessToken>, net.minidev.json.JSONAware

@Immutable
public final class BearerAccessToken
extends AccessToken

Bearer access token. This class is immutable.

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:

Author:
Vladimir Dzhuvinov

Field Summary
 
Fields inherited from class com.nimbusds.oauth2.sdk.id.Identifier
DEFAULT_BYTE_LENGTH
 
Constructor Summary
BearerAccessToken()
          Creates a new minimal bearer access token with a randomly generated value.
BearerAccessToken(int length)
          Creates a new minimal bearer access token with a randomly generated value of the specified length.
BearerAccessToken(int length, long lifetime, Scope scope)
          Creates a new bearer access token with a randomly generated value of the specified length and optional lifetime and scope.
BearerAccessToken(long lifetime, Scope scope)
          Creates a new bearer access token with a randomly generated value and the specified optional lifetime and scope.
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.
 
Method Summary
 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.
 
Methods inherited from class com.nimbusds.oauth2.sdk.token.AccessToken
compareTo, getLifetime, getScope, getType, toJSONObject, toJSONString
 
Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
getValue, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BearerAccessToken

public BearerAccessToken()
Creates a new minimal bearer access token with a randomly generated value. The value will be made up of 32 mixed-case alphanumeric ASCII characters. The optional lifetime and scope are left undefined.


BearerAccessToken

public BearerAccessToken(int length)
Creates a new minimal bearer access token with a randomly generated value of the specified length. The value will be made up of mixed-case alphanumeric ASCII characters. The optional lifetime and scope are left undefined.

Parameters:
length - The number of characters. Must be a positive integer.

BearerAccessToken

public BearerAccessToken(long lifetime,
                         Scope scope)
Creates a new bearer access token with a randomly generated value and the specified optional lifetime and scope. The value will be made up of 32 mixed-case alphanumeric ASCII characters.

Parameters:
lifetime - The lifetime in seconds, 0 if not specified.
scope - The scope, null if not specified.

BearerAccessToken

public BearerAccessToken(int length,
                         long lifetime,
                         Scope scope)
Creates a new bearer access token with a randomly generated value of the specified length and optional lifetime and scope. The value will be made up of mixed-case alphanumeric ASCII characters.

Parameters:
length - The number of characters. Must be a positive integer.
lifetime - The lifetime in seconds, 0 if not specified.
scope - The scope, null if not specified.

BearerAccessToken

public BearerAccessToken(String value)
Creates a new minimal bearer access token with the specified value. The optional lifetime and scope are left undefined.

Parameters:
value - The access token value. Must not be null or empty string.

BearerAccessToken

public BearerAccessToken(String value,
                         long lifetime,
                         Scope scope)
Creates a new bearer access token with the specified value and optional lifetime and scope.

Parameters:
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.
Method Detail

toAuthorizationHeader

public String toAuthorizationHeader()
Returns the HTTP Authorization header value for this bearer access token.

Example:

 Authorization: Bearer eyJhbGciOiJIUzI1NiJ9
 

Specified by:
toAuthorizationHeader in class AccessToken
Returns:
The HTTP Authorization header.

equals

public boolean equals(Object object)
Description copied from class: Identifier
Overrides Object.equals().

Specified by:
equals in class Identifier
Parameters:
object - The object to compare to.
Returns:
true if the objects have the same value, otherwise false.

parse

public static BearerAccessToken parse(net.minidev.json.JSONObject jsonObject)
                               throws ParseException
Parses a bearer access token from a JSON object access token response.

Parameters:
jsonObject - The JSON object to parse. Must not be null.
Returns:
The bearer access token.
Throws:
ParseException - If the JSON object couldn't be parsed to a bearer access token.

parse

public static BearerAccessToken parse(String header)
                               throws ParseException
Parses an HTTP Authorization header for a bearer access token.

Parameters:
header - The HTTP Authorization header value to parse. Must not be null.
Returns:
The bearer access token.
Throws:
ParseException - If the HTTP Authorization header value couldn't be parsed to a bearer access token.

parse

public static BearerAccessToken parse(HTTPRequest request)
                               throws ParseException
Parses an HTTP request for a bearer access token.

Parameters:
request - The HTTP request to parse. Must be GET or POST, and not null.
Returns:
The bearer access token.
Throws:
ParseException - If a bearer access token wasn't found in the HTTP request.


Copyright © 2013 NimbusDS. All Rights Reserved.