Package com.auth0.jwt
Class JWTCreator.Builder
java.lang.Object
com.auth0.jwt.JWTCreator.Builder
- Enclosing class:
- JWTCreator
The Builder class holds the Claims that defines the JWT to be created.
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
assertNonNull
(String name) Creates a new JWT and signs is with the given algorithmwithArrayClaim
(String name, Integer[] items) Add a custom Array Claim with the given items.withArrayClaim
(String name, Long[] items) Add a custom Array Claim with the given items.withArrayClaim
(String name, String[] items) Add a custom Array Claim with the given items.withAudience
(String... audience) Add a specific Audience ("aud") claim to the Payload.Add a custom Claim value.Add a custom Claim value.Add a custom Claim value.Add a custom Claim value.Add a custom Claim value.Add a custom Claim value.withExpiresAt
(Date expiresAt) Add a specific Expires At ("exp") claim to the Payload.withHeader
(Map<String, Object> headerClaims) Add specific Claims to set as the Header.withIssuedAt
(Date issuedAt) Add a specific Issued At ("iat") claim to the Payload.withIssuer
(String issuer) Add a specific Issuer ("iss") claim to the Payload.Add a specific JWT Id ("jti") claim to the Payload.Add a specific Key Id ("kid") claim to the Header.withNotBefore
(Date notBefore) Add a specific Not Before ("nbf") claim to the Payload.withSubject
(String subject) Add a specific Subject ("sub") claim to the Payload.
-
Field Details
-
payloadClaims
-
headerClaims
-
-
Constructor Details
-
Builder
Builder()
-
-
Method Details
-
withHeader
Add specific Claims to set as the Header.- Parameters:
headerClaims
- the values to use as Claims in the token's Header.- Returns:
- this same Builder instance.
-
withKeyId
Add a specific Key Id ("kid") claim to the Header. If theAlgorithm
used to sign this token was instantiated with a KeyProvider, the 'kid' value will be taken from that provider and this one will be ignored.- Parameters:
keyId
- the Key Id value.- Returns:
- this same Builder instance.
-
withIssuer
Add a specific Issuer ("iss") claim to the Payload.- Parameters:
issuer
- the Issuer value.- Returns:
- this same Builder instance.
-
withSubject
Add a specific Subject ("sub") claim to the Payload.- Parameters:
subject
- the Subject value.- Returns:
- this same Builder instance.
-
withAudience
Add a specific Audience ("aud") claim to the Payload.- Parameters:
audience
- the Audience value.- Returns:
- this same Builder instance.
-
withExpiresAt
Add a specific Expires At ("exp") claim to the Payload.- Parameters:
expiresAt
- the Expires At value.- Returns:
- this same Builder instance.
-
withNotBefore
Add a specific Not Before ("nbf") claim to the Payload.- Parameters:
notBefore
- the Not Before value.- Returns:
- this same Builder instance.
-
withIssuedAt
Add a specific Issued At ("iat") claim to the Payload.- Parameters:
issuedAt
- the Issued At value.- Returns:
- this same Builder instance.
-
withJWTId
Add a specific JWT Id ("jti") claim to the Payload.- Parameters:
jwtId
- the Token Id value.- Returns:
- this same Builder instance.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Add a custom Claim value.- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withArrayClaim
public JWTCreator.Builder withArrayClaim(String name, String[] items) throws IllegalArgumentException Add a custom Array Claim with the given items.- Parameters:
name
- the Claim's name.items
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withArrayClaim
public JWTCreator.Builder withArrayClaim(String name, Integer[] items) throws IllegalArgumentException Add a custom Array Claim with the given items.- Parameters:
name
- the Claim's name.items
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withArrayClaim
Add a custom Array Claim with the given items.- Parameters:
name
- the Claim's name.items
- the Claim's value.- Returns:
- this same Builder instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
sign
Creates a new JWT and signs is with the given algorithm- Parameters:
algorithm
- used to sign the JWT- Returns:
- a new JWT token
- Throws:
IllegalArgumentException
- if the provided algorithm is null.JWTCreationException
- if the claims could not be converted to a valid JSON or there was a problem with the signing key.
-
assertNonNull
-
addClaim
-