Module: JsonWebToken::Jwt
- Defined in:
- lib/json_web_token/jwt.rb
Overview
Encode claims for transmission as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure, enabling the claims to be integrity protected with a Message Authentication Code (MAC), to be later verified
Constant Summary collapse
- ALG_DEFAULT =
'HS256'
- HEADER_DEFAULT =
{ typ: 'JWT', alg: ALG_DEFAULT }
Class Method Summary collapse
-
.sign(claims, options) ⇒ String
A JSON Web Token, representing digitally signed claims.
-
.verify(jwt, options) ⇒ Hash
{ok: <the jwt claims set hash>} if the jwt verifies, or {error: ‘Invalid’} otherwise.
Class Method Details
.sign(claims, options) ⇒ String
Returns a JSON Web Token, representing digitally signed claims.
28 29 30 31 32 33 |
# File 'lib/json_web_token/jwt.rb', line 28 def sign(claims, ) = (claims) header = config_header() return Jws.(header, ) if header[:alg] == 'none' Jws.sign(header, , [:key]) end |
.verify(jwt, options) ⇒ Hash
Returns {ok: <the jwt claims set hash>} if the jwt verifies, or {error: ‘Invalid’} otherwise.
45 46 47 48 |
# File 'lib/json_web_token/jwt.rb', line 45 def verify(jwt, ) alg = [:alg] || ALG_DEFAULT payload(Jws.verify(jwt, alg, [:key])) end |