Skip to content

Instance Method

add(hmac:digestAlgorithm:kid:parser:serializer:)

Adds an HMAC key to the collection.
@discardableResult func add(hmac key: HMACKey, digestAlgorithm: DigestAlgorithm, kid: JWKIdentifier? = nil, parser: some JWTParser = DefaultJWTParser(), serializer: some JWTSerializer = DefaultJWTSerializer()) -> Self

Parameters

key

The SymmetricKey used for HMAC signing. This key should be kept confidential and secure, as it can be used for both signing and verification.

kid

An optional JWKIdentifier (Key ID). If given, it is used in the JWT kid header field to identify this key.

Return Value

The same instance of the collection (Self), enabling method chaining.

Discussion

Example Usage:

let collection = await JWTKeyCollection()
    .addHS256(key: "mySecretKey")