Fix bug where JSON-initialized claims don't emit proper B64 when stringified.
This commit is contained in:
parent
60f52cb22f
commit
20de51281e
@ -59,7 +59,7 @@ proc initJwtClaims*(n: JsonNode): JwtClaims =
|
|||||||
## Create a JwtClaims from a given set of claims as a JsonNOde
|
## Create a JwtClaims from a given set of claims as a JsonNOde
|
||||||
|
|
||||||
return JwtClaims(
|
return JwtClaims(
|
||||||
rawB64: $n,
|
rawB64: b64UrlEncode($n),
|
||||||
json: n,
|
json: n,
|
||||||
iss: n.optStrVal("iss"),
|
iss: n.optStrVal("iss"),
|
||||||
sub: n.optStrVal("sub"),
|
sub: n.optStrVal("sub"),
|
||||||
|
@ -22,6 +22,17 @@ suite "jwt_full/claims":
|
|||||||
sampleClaims["name"].isSome
|
sampleClaims["name"].isSome
|
||||||
sampleClaims["name"].get.getStr == "John Doe"
|
sampleClaims["name"].get.getStr == "John Doe"
|
||||||
|
|
||||||
|
test "initClaims(json)":
|
||||||
|
let jsonClaims = initJwtClaims(parseJson(sampleJwtClaimsDecoded))
|
||||||
|
|
||||||
|
check:
|
||||||
|
jsonClaims.sub.isSome
|
||||||
|
jsonClaims.sub.get == "abc"
|
||||||
|
jsonClaims["name"].isSome
|
||||||
|
jsonClaims["name"].get.getStr == "John Doe"
|
||||||
|
jsonClaims.iss.isNone
|
||||||
|
$jsonClaims == "eyJzdWIiOiJhYmMiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9"
|
||||||
|
|
||||||
test "round trip":
|
test "round trip":
|
||||||
let rfcClaims1 = initJwtClaims(rfc7519_S31_ClaimsB64)
|
let rfcClaims1 = initJwtClaims(rfc7519_S31_ClaimsB64)
|
||||||
let rfcClaims2 = initJwtClaims($rfcClaims1)
|
let rfcClaims2 = initJwtClaims($rfcClaims1)
|
||||||
|
@ -24,7 +24,7 @@ suite "jwt_full/jws":
|
|||||||
|
|
||||||
check sampleJwt == $sign(
|
check sampleJwt == $sign(
|
||||||
header = initJoseHeader(parseJson(sampleJwtHeaderDecoded)),
|
header = initJoseHeader(parseJson(sampleJwtHeaderDecoded)),
|
||||||
payload = $initJwtClaims(parseJson(sampleJwtClaimsDecoded)),
|
payload = sampleJwtClaimsDecoded,
|
||||||
key = initJwk(parseJson(sampleJwtKey)))
|
key = initJwk(parseJson(sampleJwtKey)))
|
||||||
|
|
||||||
test "HS256 - verify":
|
test "HS256 - verify":
|
||||||
|
Loading…
Reference in New Issue
Block a user