Package com.nimbusds.oauth2.sdk.device
Class UserCode
java.lang.Object
com.nimbusds.oauth2.sdk.id.Identifier
com.nimbusds.oauth2.sdk.device.UserCode
- All Implemented Interfaces:
Serializable
,Comparable<Identifier>
,net.minidev.json.JSONAware
User code.
Related specifications:
- OAuth 2.0 Device Authorization Grant (RFC 8628)
- See Also:
-
Field Summary
FieldsFields inherited from class com.nimbusds.oauth2.sdk.id.Identifier
DEFAULT_BYTE_LENGTH, secureRandom
-
Constructor Summary
ConstructorsConstructorDescriptionUserCode()
Creates a new user code with a randomly generated value with 8 characters fromLETTER_CHAR_SET
, in the formWDJB-MJHT
.Creates a new user code with the specified value and theLETTER_CHAR_SET
.Creates a new user code with a randomly generated value from the specified charset and length.Creates a new user code with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(Identifier other) boolean
Returns the character set used by thisUserCode
.Returns the value with all invalid characters removed.int
hashCode()
static String
stripIllegalChars
(String value, String charset) Removes all characters fromvalue
that are not incharset
.Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
getValue, toJSONString, toString, toStringList
-
Field Details
-
LETTER_CHAR_SET
- See Also:
-
DIGIT_CHAR_SET
- See Also:
-
-
Constructor Details
-
UserCode
Creates a new user code with the specified value.- Parameters:
value
- The code value. Must not benull
or empty string.charset
- The character set used by the identifier. The identifier can only contain characters from this set. Ifnull
, all characters are allowed.
-
UserCode
Creates a new user code with the specified value and theLETTER_CHAR_SET
.- Parameters:
value
- The code value. Must not benull
or empty string.
-
UserCode
public UserCode()Creates a new user code with a randomly generated value with 8 characters fromLETTER_CHAR_SET
, in the formWDJB-MJHT
. -
UserCode
Creates a new user code with a randomly generated value from the specified charset and length. A dash is added every 4 characters.- Parameters:
charset
- The character set used by the identifier. The identifier will contain characters from this set. Must not benull
or empty string.length
- The length of the value to generate.
-
-
Method Details
-
getCharset
Returns the character set used by thisUserCode
.- Returns:
- The character set, or
null
if unspecified.
-
getStrippedValue
Returns the value with all invalid characters removed.- Returns:
- The value with all invalid characters removed.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Identifier>
- Overrides:
compareTo
in classIdentifier
-
hashCode
- Overrides:
hashCode
in classIdentifier
-
equals
- Overrides:
equals
in classIdentifier
-
stripIllegalChars
Removes all characters fromvalue
that are not incharset
.- Parameters:
value
- The code value.charset
- The allowed characters invalue
. Ifnull
all characters are retained.- Returns:
- The
value
with all invalid characters removed.
-