module JsonWebToken
Top level interface, or API, to sign and verify a JSON Web Token (JWT) @see tools.ietf.org/html/rfc7519
Constants
- VERSION
Public Instance Methods
sign(claims, options)
click to toggle source
@param claims [Hash] a collection of name/value pairs asserting information about a subject @param options [Hash] specify the desired signing algorithm and signing key @return [String] a JSON Web Token, representing digitally signed claims @example
claims = {iss: 'joe', exp: 1300819380, :'http://example.com/is_root' => true} options = {alg: 'HS256', key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C'} JsonWebToken.sign(claims, options) # => 'eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4'
# File lib/json_web_token.rb, line 17 def sign(claims, options) Jwt.sign(claims, options) end
verify(jwt, options)
click to toggle source
@param jwt [String] a JSON Web Token @param options [Hash] specify the desired verifying algorithm and verifying key @return [Hash] +{ok: < the jwt claims set hash >}+ if the jwt verifies,
or +{error: 'Invalid'}+ otherwise
@example
jwt = 'eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4' options = {alg: 'HS256', key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C'} JsonWebToken.verify(jwt, options) # => {ok: {iss: 'joe', exp: 1300819380, :'http://example.com/is_root' => true}}
# File lib/json_web_token.rb, line 30 def verify(jwt, options) Jwt.verify(jwt, options) end