001package com.nimbusds.oauth2.sdk.token; 002 003 004import net.minidev.json.JSONObject; 005 006import com.nimbusds.oauth2.sdk.id.Identifier; 007 008 009/** 010 * The base abstract class for access and refresh tokens. Concrete extending 011 * classes should be immutable. 012 * 013 * <p>Related specifications: 014 * 015 * <ul> 016 * <li>OAuth 2.0 (RFC 6749), sections 1.4 and 1.5. 017 * </ul> 018 */ 019public abstract class Token extends Identifier { 020 021 022 /** 023 * Creates a new token with the specified value. 024 * 025 * @param value The token value. Must not be {@code null} or empty 026 * string. 027 */ 028 protected Token(final String value) { 029 030 super(value); 031 } 032 033 034 /** 035 * Creates a new token with a randomly generated value of the specified 036 * byte length, Base64URL-encoded. 037 * 038 * @param byteLength The byte length of the value to generate. Must be 039 * greater than one. 040 */ 041 protected Token(final int byteLength) { 042 043 super(byteLength); 044 } 045 046 047 /** 048 * Creates a new token with a randomly generated 256-bit (32-byte) 049 * value, Base64URL-encoded. 050 */ 051 protected Token() { 052 053 super(); 054 } 055 056 057 /** 058 * Returns the token parameters as a JSON object, as required for the 059 * composition of an access token response. See OAuth 2.0 (RFC 6749), 060 * section 5.1. 061 * 062 * <p>Note that JSONObject implements {@literal Map<String,Object>}. 063 * 064 * <p>Example: 065 * 066 * <pre> 067 * { 068 * "access_token" : "2YotnFZFEjr1zCsicMWpAA", 069 * "token_type" : "example", 070 * "expires_in" : 3600, 071 * "example_parameter" : "example_value" 072 * } 073 * </pre> 074 * 075 * @return The token parameters as a JSON object. 076 */ 077 public abstract JSONObject toJSONObject(); 078}