Allow createSignedJwt to accept string keys.
This commit is contained in:
parent
4cc2a4dee5
commit
abe03ffc55
@ -140,7 +140,7 @@ proc sign*(
|
|||||||
result.compactSerialization =
|
result.compactSerialization =
|
||||||
some($header & "." & result.payloadB64 & "." & signatureB64)
|
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
|
## Create a JWS signing a set of JWT claims. The returned JWS will be a valid
|
||||||
## JWT.
|
## JWT.
|
||||||
sign($claims, header, key, payloadIsB64Encoded = true)
|
sign($claims, header, key, payloadIsB64Encoded = true)
|
||||||
|
@ -64,10 +64,17 @@ proc toJWT*(encoded: string): JWT = initJWT(encoded)
|
|||||||
proc createSignedJwt*(
|
proc createSignedJwt*(
|
||||||
header: JoseHeader,
|
header: JoseHeader,
|
||||||
claims: JwtClaims,
|
claims: JwtClaims,
|
||||||
key: JWK
|
key: JWK | string
|
||||||
): JWT =
|
): JWT =
|
||||||
## Create a new JWT with the given header, claims, and signed with the given
|
## Create a new JWT with the given header, claims, and signed with the given
|
||||||
## key.
|
## 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(
|
result = JWT(
|
||||||
kind: jkJWS,
|
kind: jkJWS,
|
||||||
@ -85,7 +92,7 @@ proc validateTimeClaims*(jwt: JWT) =
|
|||||||
proc validate*(
|
proc validate*(
|
||||||
jwt: JWT,
|
jwt: JWT,
|
||||||
sigAlg: JwtAlgorithm,
|
sigAlg: JwtAlgorithm,
|
||||||
key: JWK,
|
key: JWK | string,
|
||||||
validateTimeClaims = true
|
validateTimeClaims = true
|
||||||
) =
|
) =
|
||||||
|
|
||||||
@ -101,7 +108,7 @@ proc validate*(
|
|||||||
proc tryValidate*(
|
proc tryValidate*(
|
||||||
jwt: JWT,
|
jwt: JWT,
|
||||||
sigAlg: JwtAlgorithm,
|
sigAlg: JwtAlgorithm,
|
||||||
key: JWK,
|
key: JWK | string,
|
||||||
validateTimeClaims = true
|
validateTimeClaims = true
|
||||||
): bool =
|
): bool =
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user