-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
The jwt-scala library has a number of integrations with json libraries to make it easy to decode JWT claims (which are in json). Since jsoniter doesn't have an AST this can't be achieved directly through their JwtJsonCommon class, instead an implementer needs to implement JwtCore[H, C]. One solution is to create a custom header and claim for your specific needs, but thats very cumbersome. The JwtClaim class is defined:
class JwtClaim(
val content: String,
val issuer: Option[String],
val subject: Option[String],
val audience: Option[Set[String]],
val expiration: Option[Long],
val notBefore: Option[Long],
val issuedAt: Option[Long],
val jwtId: Option[String]
)where each field has a jwt associated well-defined field e.g. issuer => iss in json, except content which is simply a string encoded json object containing all the "extra" fields. That is, those fields not explicitly defined in the spec but added for specific usage by the user. What is is needed is a custom codec that will:
- populate the standard fields
- treat everything else as a "raw" field and add it to the stringified body
contentfield.
As an example:
{
"iss": "abc123",
"sub": "efg456",
"iat": 0,
"https://example.com/roles": ["admin", "super_admin"],
"https://sub.example.com/tenant_id": "zzzzzzzz"
}We would expect the claim:
JwtClaim(
issuer = Some("abc123"),
subject = Some("efg456"),
issuedAt = Some(0L),
content = """{"https://example.com/roles": ["admin", "super_admin"],"https://sub.example.com/tenant_id": "zzzzzzzz"}"""
)