diff --git a/src/main/jwt_full/claims.nim b/src/main/jwt_full/claims.nim index f08bf5a..25228db 100644 --- a/src/main/jwt_full/claims.nim +++ b/src/main/jwt_full/claims.nim @@ -59,7 +59,7 @@ proc initJwtClaims*(n: JsonNode): JwtClaims = ## Create a JwtClaims from a given set of claims as a JsonNOde return JwtClaims( - rawB64: $n, + rawB64: b64UrlEncode($n), json: n, iss: n.optStrVal("iss"), sub: n.optStrVal("sub"), diff --git a/src/test/unit/tclaims.nim b/src/test/unit/tclaims.nim index dcbb156..ef381e3 100644 --- a/src/test/unit/tclaims.nim +++ b/src/test/unit/tclaims.nim @@ -22,6 +22,17 @@ suite "jwt_full/claims": sampleClaims["name"].isSome 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": let rfcClaims1 = initJwtClaims(rfc7519_S31_ClaimsB64) let rfcClaims2 = initJwtClaims($rfcClaims1) diff --git a/src/test/unit/tjws.nim b/src/test/unit/tjws.nim index 5d5fb30..72e9fed 100644 --- a/src/test/unit/tjws.nim +++ b/src/test/unit/tjws.nim @@ -24,7 +24,7 @@ suite "jwt_full/jws": check sampleJwt == $sign( header = initJoseHeader(parseJson(sampleJwtHeaderDecoded)), - payload = $initJwtClaims(parseJson(sampleJwtClaimsDecoded)), + payload = sampleJwtClaimsDecoded, key = initJwk(parseJson(sampleJwtKey))) test "HS256 - verify":