- java.lang.Object
-
- io.helidon.security.jwt.JwtHeaders
-
public class JwtHeaders extends Object
Representation of the header section of a JWT. This can be used to partially parse a token to understand what kind of processing should be done further, whetherSignedJwt
orEncryptedJwt
.- See Also:
parseToken(String)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JwtHeaders.Builder
Fluent API builder to create JWT Header.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<String>
algorithm()
Algorithm claim.Optional<List<String>>
audience()
Audience claim.static JwtHeaders.Builder
builder()
Create a new builder for header claims.Optional<String>
contentType()
Content type claim.protected static String
decode(String base64, Errors.Collector collector, String description)
Optional<String>
encryption()
Encryption algorithm claim.Optional<JsonValue>
headerClaim(String claim)
Get a claim by its name from header.JsonObject
headerJson()
Create a JSON header object.Optional<String>
issuer()
Issuer claim.Optional<String>
keyId()
Key id claim.protected static JsonObject
parseJson(String jsonString, Errors.Collector collector, String base64, String description)
static JwtHeaders
parseToken(String token)
Parse a token to retrieve the JWT header.Optional<String>
subject()
Subject claim.Optional<String>
type()
Type claim.
-
-
-
Method Detail
-
builder
public static JwtHeaders.Builder builder()
Create a new builder for header claims.- Returns:
- a new builder
-
parseToken
public static JwtHeaders parseToken(String token)
Parse a token to retrieve the JWT header. This method only cares about the first section of the token, and ignores the rest (even if not valid). Text before the first dot is considered to be base64 value of the header JSON.- Parameters:
token
- token, expected to be JWT (encrypted or signed)- Returns:
- header parsed from the token
- Throws:
JwtException
- in case the token is not valid
-
headerJson
public JsonObject headerJson()
Create a JSON header object.- Returns:
- JsonObject for header
-
headerClaim
public Optional<JsonValue> headerClaim(String claim)
Get a claim by its name from header.- Parameters:
claim
- name of a claim- Returns:
- claim value if present
-
algorithm
public Optional<String> algorithm()
Algorithm claim.- Returns:
- algorithm or empty if claim is not defined
-
encryption
public Optional<String> encryption()
Encryption algorithm claim.- Returns:
- algorithm or empty if not encrypted
-
contentType
public Optional<String> contentType()
Content type claim.- Returns:
- content type or empty if claim is not defined
-
keyId
public Optional<String> keyId()
Key id claim.- Returns:
- key id or empty if claim is not defined
-
subject
public Optional<String> subject()
Subject claim.- Returns:
- subject or empty if claim is not defined
-
issuer
public Optional<String> issuer()
Issuer claim.- Returns:
- Issuer or empty if claim is not defined
-
audience
public Optional<List<String>> audience()
Audience claim.- Returns:
- audience or empty optional if claim is not defined; list would be empty if the audience claim is defined as an empty array
-
decode
protected static String decode(String base64, Errors.Collector collector, String description)
-
parseJson
protected static JsonObject parseJson(String jsonString, Errors.Collector collector, String base64, String description)
-
-