Class Tokens

java.lang.Object
com.nimbusds.oauth2.sdk.token.Tokens
Direct Known Subclasses:
OIDCTokens

public class Tokens extends Object
Access and optional refresh token.
  • Constructor Details

    • Tokens

      public Tokens(AccessToken accessToken, RefreshToken refreshToken)
      Creates a new tokens instance.
      Parameters:
      accessToken - The access token. Must not be null.
      refreshToken - The refresh token. If none null.
  • Method Details

    • getAccessToken

      Returns the access token.
      Returns:
      The access token.
    • getBearerAccessToken

      Returns the access token as type bearer.
      Returns:
      The bearer access token, null if the type is different.
    • getDPoPAccessToken

      Returns the access token as type DPoP.
      Returns:
      The DPoP access token, null if the type is different.
    • getRefreshToken

      Returns the optional refresh token.
      Returns:
      The refresh token, null if none.
    • getParameterNames

      Returns the token parameter names for the included tokens.
      Returns:
      The token parameter names.
    • getMetadata

      Returns the optional modifiable token metadata. Intended for server environments.
      Returns:
      The token metadata.
    • toJSONObject

      public net.minidev.json.JSONObject toJSONObject()
      Returns the JSON object representation of this token pair.

      Example JSON object:

       {
         "access_token"  : "dZdt8BlltORMTz5U",
         "refresh_token" : "E87zjAoeNXaSoF1U"
       }
       
      Returns:
      The JSON object representation.
    • toOIDCTokens

      Casts to OpenID Connect tokens.
      Returns:
      The OpenID Connect tokens (including an ID token).
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parse

      public static Tokens parse(net.minidev.json.JSONObject jsonObject) throws ParseException
      Parses an access and optional refresh token from the specified JSON object.
      Parameters:
      jsonObject - The JSON object to parse. Must not be null.
      Returns:
      The tokens.
      Throws:
      ParseException - If the JSON object couldn't be parsed to a tokens instance.