Class: JsonWebToken
- Inherits:
-
Object
- Object
- JsonWebToken
- Defined in:
- lib/generators/jwt_api/templates/initializers/json_web_token.rb
Overview
JSON Web Token class
Instance Method Summary collapse
- #decode(token) ⇒ Object
- #encode(payload) ⇒ Object
-
#initialize(key = Rails.application.credentials[:jwt_secret], algorithm = 'HS256') ⇒ JsonWebToken
constructor
A new instance of JsonWebToken.
Constructor Details
#initialize(key = Rails.application.credentials[:jwt_secret], algorithm = 'HS256') ⇒ JsonWebToken
Returns a new instance of JsonWebToken.
5 6 7 8 |
# File 'lib/generators/jwt_api/templates/initializers/json_web_token.rb', line 5 def initialize(key = Rails.application.credentials[:jwt_secret], algorithm = 'HS256') @key = key @algorithm = algorithm end |
Instance Method Details
#decode(token) ⇒ Object
14 15 16 |
# File 'lib/generators/jwt_api/templates/initializers/json_web_token.rb', line 14 def decode(token) JWT.decode(token, @key, @algorithm) end |
#encode(payload) ⇒ Object
10 11 12 |
# File 'lib/generators/jwt_api/templates/initializers/json_web_token.rb', line 10 def encode(payload) JWT.encode(payload, @key, @algorithm) end |