Allow createSignedJwt to accept string keys.

This commit is contained in:
Jonathan Bernard 2021-12-25 18:25:16 -06:00
parent 4cc2a4dee5
commit abe03ffc55
2 changed files with 11 additions and 4 deletions

View File

@ -140,7 +140,7 @@ proc sign*(
result.compactSerialization =
some($header & "." & result.payloadB64 & "." & signatureB64)
proc sign*(claims: JwtClaims, header: JoseHeader, key: JWK): JWS =
proc sign*(claims: JwtClaims, header: JoseHeader, key: JWK | string): JWS =
## Create a JWS signing a set of JWT claims. The returned JWS will be a valid
## JWT.
sign($claims, header, key, payloadIsB64Encoded = true)

View File

@ -64,10 +64,17 @@ proc toJWT*(encoded: string): JWT = initJWT(encoded)
proc createSignedJwt*(
header: JoseHeader,
claims: JwtClaims,
key: JWK
key: JWK | string
): JWT =
## Create a new JWT with the given header, claims, and signed with the given
## key.
##
## *header* can be easily created with `initJoseHeader <>`_.
## *claims* can be easily created with `initClaims <>`_.
## *key* is expected to be either a `JWK <>`_ or a string. If a string is
## supplied, it is expected to be the binary value of the key when using
## HSxxx algorithms, and a PEM representing the private key for RSxxx and
## ECxxx algorithms.
result = JWT(
kind: jkJWS,
@ -85,7 +92,7 @@ proc validateTimeClaims*(jwt: JWT) =
proc validate*(
jwt: JWT,
sigAlg: JwtAlgorithm,
key: JWK,
key: JWK | string,
validateTimeClaims = true
) =
@ -101,7 +108,7 @@ proc validate*(
proc tryValidate*(
jwt: JWT,
sigAlg: JwtAlgorithm,
key: JWK,
key: JWK | string,
validateTimeClaims = true
): bool =