Package com.bastiaanjansen.jwt
Class JWT.Builder
java.lang.Object
com.bastiaanjansen.jwt.JWT.Builder
- Enclosing class:
- JWT
public static class JWT.Builder extends Object
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description JWTbuild()Create a new JWT instanceStringsign()Creates a new JWTStringsign(Map<String,?> payload)Creates a new JWT with additional payloadJWT.BuilderwithAudience(String... audience)Add an audience (aud) claim to payloadJWT.BuilderwithClaim(String name, Object value)Add a claim to the payloadJWT.BuilderwithClaim(Map<String,?> claims)Add multiple claims to payloadJWT.BuilderwithContentType(String contentType)Add a content type (cty) claim to headerJWT.BuilderwithExpirationTime(long timeSinceEpoch)Add an expiration time (exp) to payloadJWT.BuilderwithExpirationTime(Date expirationTime)Add an expiration time (exp) to payloadJWT.BuilderwithHeader(Header header)Set the header.JWT.BuilderwithHeader(String name, String value)Add a header claimJWT.BuilderwithID(String id)Add a key ID (kid) to the header claimsJWT.BuilderwithIssuedAt(long timeSinceEpoch)Add an issued at (iat) claim to payloadJWT.BuilderwithIssuedAt(Date issuedAt)Add an issued at (iat) claim to payloadJWT.BuilderwithIssuer(String issuer)Add an issuer (iss) claim to payloadJWT.BuilderwithNotBefore(long timeSinceEpoch)Add a not-before (nbf) claim to payloadJWT.BuilderwithNotBefore(Date notBefore)Add a not-before (nbf) claim to payloadJWT.BuilderwithPayload(Payload payload)Set the payload.JWT.BuilderwithSubject(String subject)Add a subject (sub) claim to payloadJWT.BuilderwithType(String type)Add type (typ) claim to header
-
Constructor Details
-
Builder
Creates a new JWT Builder instance- Parameters:
algorithm- algorithm to use when signing JWT
-
-
Method Details
-
withType
Add type (typ) claim to header- Parameters:
type- type header- Returns:
- the same builder instance
-
withContentType
Add a content type (cty) claim to header- Parameters:
contentType- content type value- Returns:
- the same builder instance
-
withIssuer
Add an issuer (iss) claim to payload- Parameters:
issuer- issuer value- Returns:
- the same builder instance
-
withSubject
Add a subject (sub) claim to payload- Parameters:
subject- subject value- Returns:
- the same builder instance
-
withAudience
Add an audience (aud) claim to payload- Parameters:
audience- audience value- Returns:
- the same builder instance
-
withExpirationTime
Add an expiration time (exp) to payload- Parameters:
expirationTime- expiration time as date- Returns:
- the same builder instance
-
withExpirationTime
Add an expiration time (exp) to payload- Parameters:
timeSinceEpoch- Milliseconds since January 1, 1970- Returns:
- the same builder instance
-
withNotBefore
Add a not-before (nbf) claim to payload- Parameters:
notBefore- not before date object- Returns:
- the same builder instance
-
withNotBefore
Add a not-before (nbf) claim to payload- Parameters:
timeSinceEpoch- Milliseconds since January 1, 1970- Returns:
- the same builder instance
-
withIssuedAt
Add an issued at (iat) claim to payload- Parameters:
issuedAt- issued at date- Returns:
- the same builder instance
-
withIssuedAt
Add an issued at (iat) claim to payload- Parameters:
timeSinceEpoch- Milliseconds since January 1, 1970- Returns:
- the same builder instance
-
withID
Add a key ID (kid) to the header claims- Parameters:
id- the key ID- Returns:
- the same builder instance
-
withHeader
Add a header claim- Parameters:
name- name of header claimvalue- value of header claim
-
withHeader
Set the header. This will replace the current header- Parameters:
header- Header data- Returns:
- the same builder instance
-
withPayload
Set the payload. This will replace the current payload- Parameters:
payload- Payload data- Returns:
- the same builder instance
-
withClaim
Add a claim to the payload- Parameters:
name- name of payload claimvalue- value of payload claim- Returns:
- the same builder instance
-
withClaim
Add multiple claims to payload- Parameters:
claims- the values used in the payload
-
sign
Creates a new JWT- Returns:
- a new JWT
- Throws:
JWTCreationException- when the JWT could not be created
-
sign
Creates a new JWT with additional payload- Parameters:
payload- map of additional payload- Returns:
- A new JWT
- Throws:
JWTCreationException- when the JWT could not be created
-
build
Create a new JWT instance- Returns:
- New JWT instance
- Throws:
JWTCreationException
-