001package com.nimbusds.oauth2.sdk; 002 003 004import net.jcip.annotations.Immutable; 005 006import com.nimbusds.oauth2.sdk.id.Identifier; 007 008 009/** 010 * Authorisation code. A maximum authorization code lifetime of 10 minutes is 011 * recommended. This class is immutable. 012 * 013 * <p>Related specifications: 014 * 015 * <ul> 016 * <li>OAuth 2.0 (RFC 6749), section 1.3.1. 017 * </ul> 018 * 019 * @author Vladimir Dzhuvinov 020 */ 021@Immutable 022public final class AuthorizationCode extends Identifier { 023 024 025 /** 026 * Creates a new authorisation code with the specified value. 027 * 028 * @param value The code value. Must not be {@code null} or empty 029 * string. 030 */ 031 public AuthorizationCode(final String value) { 032 033 super(value); 034 } 035 036 037 /** 038 * Creates a new authorisation code with a randomly generated value of 039 * the specified byte length, Base64URL-encoded. 040 * 041 * @param byteLength The byte length of the value to generate. Must be 042 * greater than one. 043 */ 044 public AuthorizationCode(final int byteLength) { 045 046 super(byteLength); 047 } 048 049 050 /** 051 * Creates a new authorisation code with a randomly generated 256-bit 052 * (32-byte) value, Base64URL-encoded. 053 */ 054 public AuthorizationCode() { 055 056 super(); 057 } 058 059 060 @Override 061 public boolean equals(final Object object) { 062 063 return object != null && 064 object instanceof AuthorizationCode && 065 this.toString().equals(object.toString()); 066 } 067}