Package com.nimbusds.openid.connect.sdk
Class Nonce
java.lang.Object
com.nimbusds.oauth2.sdk.id.Identifier
com.nimbusds.openid.connect.sdk.Nonce
- All Implemented Interfaces:
Serializable
,Comparable<Identifier>
,net.minidev.json.JSONAware
Nonce. This is a random, unique string value to associate a user-session
with an ID Token and to mitigate replay attacks.
Example generation of a 16 byte random nonce:
Nonce nonce = new Nonce(16);
Related specifications:
- OpenID Connect Core 1.0
- See Also:
-
Field Summary
Fields inherited from class com.nimbusds.oauth2.sdk.id.Identifier
DEFAULT_BYTE_LENGTH, secureRandom
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
static boolean
isRequired
(ResponseType responseType) Returnstrue
if the specified OAuth 2.0 response type requires a nonce.static Nonce
Parses a nonce from the specified string.Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
compareTo, getValue, hashCode, toJSONString, toString, toStringList
-
Constructor Details
-
Nonce
Creates a new nonce with the specified value.- Parameters:
value
- The nonce value. Must not benull
or empty string.
-
Nonce
Creates a new nonce with a randomly generated value of the specified byte length, Base64URL-encoded.- Parameters:
byteLength
- The byte length of the value to generate. Must be greater than one.
-
Nonce
public Nonce()Creates a new nonce with a randomly generated 256-bit (32-byte) value, Base64URL-encoded.
-
-
Method Details
-
equals
- Overrides:
equals
in classIdentifier
-
parse
Parses a nonce from the specified string.- Parameters:
s
- The string to parse,null
or empty if no nonce is specified.- Returns:
- The nonce,
null
if the parsed string wasnull
or empty.
-
isRequired
Returnstrue
if the specified OAuth 2.0 response type requires a nonce.- Parameters:
responseType
- The response type. Must not benull
.- Returns:
true
if a nonce is required,false
if not.
-