diff --git a/vlib/crypto/README.md b/vlib/crypto/README.md index 4f3878439b9fdc..76a871ef113129 100644 --- a/vlib/crypto/README.md +++ b/vlib/crypto/README.md @@ -71,9 +71,11 @@ fn main() { secret := 'your-256-bit-secret' token := make_token(secret) ok := auth_verify(secret, token) + pl := decode_payload(token) or { panic(err) } dt := sw.elapsed().microseconds() println('token: ${token}') println('auth_verify(secret, token): ${ok}') + println('decode_payload(token): ${pl}') println('Elapsed time: ${dt} uS') } @@ -93,4 +95,10 @@ fn auth_verify(secret string, token string) bool { signature_from_token := base64.url_decode(token_split[2]) return hmac.equal(signature_from_token, signature_mirror) } -``` + +fn decode_payload(token string) !JwtPayload { + token_split := token.split('.') + payload := json.decode(JwtPayload, base64.url_decode_str(token_split[1]))! + return payload +} +``` \ No newline at end of file