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 * @version $version$ (2014-01-18) 020 */ 021 public abstract class Token extends Identifier { 022 023 024 /** 025 * Creates a new token with the specified value. 026 * 027 * @param value The token value. Must not be {@code null} or empty 028 * string. 029 */ 030 protected Token(final String value) { 031 032 super(value); 033 } 034 035 036 /** 037 * Creates a new token with a randomly generated value of the specified 038 * length. The value will be made up of mixed-case alphanumeric ASCII 039 * characters. 040 * 041 * @param length The number of characters. Must be a positive integer. 042 */ 043 protected Token(final int length) { 044 045 super(length); 046 } 047 048 049 /** 050 * Creates a new token with a randomly generated value. The value will 051 * be made up of 32 mixed-case alphanumeric ASCII characters. 052 */ 053 protected Token() { 054 055 super(); 056 } 057 058 059 /** 060 * Returns the token parameters as a JSON object, as required for the 061 * composition of an access token response. See OAuth 2.0 (RFC 6749), 062 * section 5.1. 063 * 064 * <p>Note that JSONObject implements {@code Map<String,Object>}. 065 * 066 * <p>Example: 067 * 068 * <pre> 069 * { 070 * "access_token" : "2YotnFZFEjr1zCsicMWpAA", 071 * "token_type" : "example", 072 * "expires_in" : 3600, 073 * "example_parameter" : "example_value" 074 * } 075 * </pre> 076 * 077 * @return The token parameters as a JSON object. 078 */ 079 public abstract JSONObject toJSONObject(); 080 }