Class Token

java.lang.Object
com.nimbusds.oauth2.sdk.id.Identifier
com.nimbusds.oauth2.sdk.token.Token
All Implemented Interfaces:
Serializable, Comparable<Identifier>, net.minidev.json.JSONAware
Direct Known Subclasses:
AccessToken, RefreshToken, TypelessToken

public abstract class Token extends Identifier
The base abstract class for access and refresh tokens. Concrete extending classes should be immutable.

Related specifications:

  • OAuth 2.0 (RFC 6749), sections 1.4 and 1.5.
See Also:
  • Field Summary

    Fields inherited from class com.nimbusds.oauth2.sdk.id.Identifier

    DEFAULT_BYTE_LENGTH, secureRandom
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded.
    protected
    Token(int byteLength)
    Creates a new token with a randomly generated value of the specified byte length, Base64URL-encoded.
    protected
    Token(String value)
    Creates a new token with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Set<String>
    Returns the token parameter names included in the JSON object, as required for the composition of an access token response.
    abstract net.minidev.json.JSONObject
    Returns the token parameters as a JSON object, as required for the composition of an access token response.

    Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier

    compareTo, equals, getValue, hashCode, toJSONString, toString, toStringList

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Token

      protected Token(String value)
      Creates a new token with the specified value.
      Parameters:
      value - The token value. Must not be null or empty string.
    • Token

      protected Token(int byteLength)
      Creates a new token with a randomly generated value of the specified byte length, Base64URL-encoded.
      Parameters:
      byteLength - The byte length of the value to generate. Must be greater than one.
    • Token

      protected Token()
      Creates a new token with a randomly generated 256-bit (32-byte) value, Base64URL-encoded.
  • Method Details

    • getParameterNames

      public abstract Set<String> getParameterNames()
      Returns 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.
      Returns:
      The token parameter names.
    • toJSONObject

      public abstract net.minidev.json.JSONObject toJSONObject()
      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&lt;String,Object&gt;.

      Example:

       {
         "access_token"      : "2YotnFZFEjr1zCsicMWpAA",
         "token_type"        : "example",
         "expires_in"        : 3600,
         "example_parameter" : "example_value"
       }
       
      Returns:
      The token parameters as a JSON object.