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