From 8241c0209a21fdecf41e9346e4af0c16398e1e92 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 29 Oct 2018 15:17:31 +0100 Subject: [PATCH] Updated JWT README content. --- library/security/jwt/README.md | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/library/security/jwt/README.md b/library/security/jwt/README.md index c5bfd597..08cafe8b 100644 --- a/library/security/jwt/README.md +++ b/library/security/jwt/README.md @@ -2,25 +2,34 @@ JSON Web Token (JWT) http://jwt.io/ -Note: supporting only HS256 and none algorithm for signature. +Note: supporting only HS256 and none algorithm for signature, but could be extend with your own algorithm via `JWT_ALGORITHMS` (see `JWT.algorithms`, and `JWT_LOADER.algorithms`). # How to use ```eiffel - local - jwt: JWT - do - create jwt - tok := jwt.encoded_string ("[ - {"iss":"joe", "exp":1200819380,"http://example.com/is_root":true} - ]", "secret", "HS256") - if - attached jwt.decoded_string (tok, "secret", Void) as l_tok_payload and - not jwt.has_error - then - check verified: not jwt.has_unverified_token_error end - check no_error: not jwt.has_error end - print (l_tok_payload) + + example + local + jwt: JWS + tok: STRING + l_loader: JWT_LOADER + do + create jwt.make_with_json_payload ("[ + {"iss":"joe", "exp":1200819380,"http://example.com/is_root":true} + ]") + jwt.set_algorithm_to_hs256 + tok := jwt.encoded_string ("my-secret") + + create l_loader + if + attached l_loader.token (tok, Void, "my-secret", Void) as l_tok and then + not l_tok.has_error + then + print (l_tok.claimset.string) + check verified: not l_tok.has_unverified_token_error end + check no_error: not l_tok.has_error end + end end end ``` +