Module: JsonWebToken::Jwt

Defined in:
lib/json_web_token/jwt.rb

Constant Summary collapse

ALGORITHM_DEFAULT =
'HS256'
HEADER_DEFAULT =
{
  typ: 'JWT',
  alg: ALGORITHM_DEFAULT
}

Class Method Summary collapse

Class Method Details

.create(claims, options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/json_web_token/jwt.rb', line 15

def create(claims, options = {})
  message = validated_message(claims)
  header = config_header(options)
  return Jws.unsecured_jws(header, message) if header[:alg] == 'none'
  Jws.message_signature(header, message, options[:key])
end

.validate(jwt, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/json_web_token/jwt.rb', line 22

def validate(jwt, options = {})
  alg = options[:alg] || ALGORITHM_DEFAULT
  jws = Jws.validate(jwt, alg, options[:key])
  jws == 'Invalid' ? jws : Util.symbolize_keys(decoded_message_json_to_hash jws)
end