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.
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 */
020public 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         * byte length, Base64URL-encoded.
038         *
039         * @param byteLength The byte length of the value to generate. Must be
040         *                   greater than one.
041         */
042        protected Token(final int byteLength) {
043        
044                super(byteLength);
045        }
046        
047        
048        /**
049         * Creates a new token with a randomly generated 256-bit (32-byte) 
050         * value, Base64URL-encoded.
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}