Updated JWT README content.
This commit is contained in:
@@ -2,25 +2,34 @@ JSON Web Token (JWT)
|
|||||||
|
|
||||||
http://jwt.io/
|
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
|
# How to use
|
||||||
```eiffel
|
```eiffel
|
||||||
local
|
|
||||||
jwt: JWT
|
example
|
||||||
do
|
local
|
||||||
create jwt
|
jwt: JWS
|
||||||
tok := jwt.encoded_string ("[
|
tok: STRING
|
||||||
{"iss":"joe", "exp":1200819380,"http://example.com/is_root":true}
|
l_loader: JWT_LOADER
|
||||||
]", "secret", "HS256")
|
do
|
||||||
if
|
create jwt.make_with_json_payload ("[
|
||||||
attached jwt.decoded_string (tok, "secret", Void) as l_tok_payload and
|
{"iss":"joe", "exp":1200819380,"http://example.com/is_root":true}
|
||||||
not jwt.has_error
|
]")
|
||||||
then
|
jwt.set_algorithm_to_hs256
|
||||||
check verified: not jwt.has_unverified_token_error end
|
tok := jwt.encoded_string ("my-secret")
|
||||||
check no_error: not jwt.has_error end
|
|
||||||
print (l_tok_payload)
|
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
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user