com.nimbusds.oauth2.sdk.token
Class AccessToken

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
All Implemented Interfaces:
Comparable<AccessToken>, net.minidev.json.JSONAware
Direct Known Subclasses:
BearerAccessToken, TypelessAccessToken

public abstract class AccessToken
extends Token
implements Comparable<AccessToken>

The base abstract class for access tokens.

Related specifications:

Author:
Vladimir Dzhuvinov

Constructor Summary
AccessToken(AccessTokenType type)
          Creates a new minimal access token with a randomly generated value.
AccessToken(AccessTokenType type, int length)
          Creates a new minimal access token with a randomly generated value of the specified length.
AccessToken(AccessTokenType type, int length, long lifetime, Scope scope)
          Creates a new access token with a randomly generated value of the specified length and optional lifetime and scope.
AccessToken(AccessTokenType type, long lifetime, Scope scope)
          Creates a new access token with a randomly generated value and the specified optional lifetime and scope.
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 and optional lifetime and scope.
 
Method Summary
 int compareTo(AccessToken other)
           
 long getLifetime()
          Gets the lifetime of this access token.
 Scope getScope()
          Gets the scope of this access token.
 AccessTokenType getType()
          Gets the access token type.
static AccessToken parse(net.minidev.json.JSONObject jsonObject)
          Parses an access token from a JSON object access token response.
static AccessToken parse(String header)
          Parses an Authorization HTTP request header value for an access token.
abstract  String toAuthorizationHeader()
          Returns the Authorization HTTP request header value for this access token.
 net.minidev.json.JSONObject toJSONObject()
          Returns the token parameters as a JSON object, as required for the composition of an access token response.
 String toJSONString()
          Returns the JSON string representation of this identifier.
 
Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
equals, getValue, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AccessToken

public AccessToken(AccessTokenType type)
Creates a new minimal 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.

Parameters:
type - The access token type. Must not be null.

AccessToken

public AccessToken(AccessTokenType type,
                   int length)
Creates a new minimal 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:
type - The access token type. Must not be null.
length - The number of characters. Must be a positive integer.

AccessToken

public AccessToken(AccessTokenType type,
                   long lifetime,
                   Scope scope)
Creates a new 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:
type - The access token type. Must not be null.
lifetime - The lifetime in seconds, 0 if not specified.
scope - The scope, null if not specified.

AccessToken

public AccessToken(AccessTokenType type,
                   int length,
                   long lifetime,
                   Scope scope)
Creates a new 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:
type - The access token type. Must not be null.
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.

AccessToken

public AccessToken(AccessTokenType type,
                   String value)
Creates a new minimal access token with the specified value. The optional lifetime and scope are left undefined.

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

AccessToken

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

Parameters:
type - The access token type. Must not be null.
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

getType

public AccessTokenType getType()
Gets the access token type.

Returns:
The access token type.

getLifetime

public long getLifetime()
Gets the lifetime of this access token.

Returns:
The lifetime in seconds, 0 if not specified.

getScope

public Scope getScope()
Gets the scope of this access token.

Returns:
The scope, null if not specified.

toJSONObject

public net.minidev.json.JSONObject toJSONObject()
Description copied from class: Token
Returns 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:
toJSONObject in class Token
Returns:
The token parameters as a JSON object.

toJSONString

public String toJSONString()
Description copied from class: Identifier
Returns the JSON string representation of this identifier.

Specified by:
toJSONString in interface net.minidev.json.JSONAware
Overrides:
toJSONString in class Identifier
Returns:
The JSON string.

toAuthorizationHeader

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

Returns:
The Authorization header value.

compareTo

public int compareTo(AccessToken other)
Specified by:
compareTo in interface Comparable<AccessToken>

parse

public static AccessToken parse(net.minidev.json.JSONObject jsonObject)
                         throws ParseException
Parses an access token from a JSON object access token response. Only bearer access tokens are supported.

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

parse

public static AccessToken parse(String header)
                         throws ParseException
Parses an Authorization HTTP request header value for an access token. Only bearer access token are supported.

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


Copyright © 2013 NimbusDS. All Rights Reserved.