public interface JWT extends JWS
JWT
represents a parsed JWT (JSON Web Token) Object.
A JWT consists of three sections:
Header
The header consist of two parts:
{ "type": "JWT", "alg": "HS256" }
Payload
The payload contains the data for the JWT. These are known as JWT Claims. The claims contain all the information regarding the JWT. Typically the JWT payload is in JSON format
Registered Claims
Registered claims are not mandatory but they are reserved names outline in RFC 7519, These include:
Public Claims
These are claims that are created, for example name, email etc..
An example payload:
{ "iss": "ebasetech.com", "exp": 1300819380, "name": "John Doe", "admin": true }
Signature The third and final part of our JSON Web Token is going to be the signature. The signature is omitted if the algorithm in the header is set to none. The signature is created by signing the concatenated base64Encoded header and payload:
Example of a HS256 signature:
var encodedString = base64UrlEncode(header) + "." + base64UrlEncode(payload); HMACSHA256(encodedString, 'secret');
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
getAudience() |
java.lang.Object |
getClaim(java.lang.String claimName)
Returns a claim value for a given name
|
java.lang.Object[] |
getClaimArray(java.lang.String claimName)
Returns a claim array value for a given name
|
java.lang.String[] |
getClaimNames() |
java.util.Date |
getExpiration() |
java.util.Date |
getIssuedAt() |
java.lang.String |
getIssuer() |
java.lang.String |
getJWTId() |
java.util.Date |
getNotBefore() |
java.lang.String |
getSubject() |
boolean |
isExpired() |
getHeader, getPayload, getSignature, isSigned, verifyFileJWKSet, verifyFromKeyStore, verifyHMAC, verifyInputStreamJWKSet, verifyPublicKey, verifyRemoteJWKSet
java.lang.Object getClaim(java.lang.String claimName)
claimName
- of the claim valuejava.lang.Object[] getClaimArray(java.lang.String claimName)
claimName
- of the claim valuejava.util.Date getExpiration()
exp
) timestamp or null if not present.boolean isExpired()
exp
) claim is not set, false is returned.java.util.Date getIssuedAt()
iat
) or (null
) if not present. If present, this value is the timestamp when the JWT was created.java.util.Date getNotBefore()
nbf
) or (null
) if not present.java.lang.String[] getAudience()
aud
) value or (null
) if not present.java.lang.String getJWTId()
jti
) value or (null
) if not present. This value is a unique identifier for the JWT. If available, this value is expected to be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object. The ID can be used to prevent the JWT from being replayed.java.lang.String getIssuer()
iss
) value or (null
) if not present.java.lang.String getSubject()
sub
) value or (null
) if not present.java.lang.String[] getClaimNames()
getClaim(String)