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
A JWT claims set 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 a JWT claims set if the jwt verifies, or error: ‘Invalid’ otherwise.
44 45 46 47 48 |
# File 'lib/json_web_token/jwt.rb', line 44 def verify(jwt, ) alg = [:alg] || ALG_DEFAULT jws = Jws.verify(jwt, alg, [:key]) jws ? Util.symbolize_keys( jws) : {error: 'invalid'} end |