JwtInstance

sealed class JwtInstance(source)

Sealed base class for a parsed or constructed JWT token instance.

The two concrete variants correspond to the two main JWT token types defined in the JOSE specifications:

  • Jws — a signed token (JWS, RFC 7515) with three compact-serialization parts: header.payload.signature.

  • Jwe — an encrypted token (JWE, RFC 7516) with five compact-serialization parts: header.encryptedKey.iv.ciphertext.tag.

Use compact to obtain the compact-serialized string, or getPayload / getHeader to deserialize the payload or header into a typed object.

See also

Inheritors

Types

Link copied to clipboard

Represents a JWE (encrypted) token with five compact-serialization parts.

Link copied to clipboard

Represents a JWS (signed) token with one or more signatures.

Properties

Link copied to clipboard
abstract val header: JwtHeader

The JOSE header of the token.

Link copied to clipboard
abstract val payload: JwtPayload

The payload (claims set) of the token.

Functions

Link copied to clipboard
abstract fun compact(): String

Returns the compact serialization of this token.

Link copied to clipboard
inline fun <T> getHeader(jsonInstance: Json = Jwt.defaultJsonParser): T

Deserializes the token header as type T.

fun <T> getHeader(serializer: KSerializer<T>, jsonInstance: Json = Jwt.defaultJsonParser): T

Deserializes the token header using the given serializer.

Link copied to clipboard
inline fun <T> getPayload(jsonInstance: Json = Jwt.defaultJsonParser): T

Deserializes the token payload as type T.

fun <T> getPayload(serializer: KSerializer<T>, jsonInstance: Json = Jwt.defaultJsonParser): T

Deserializes the token payload using the given serializer.

Link copied to clipboard
open override fun toString(): String