Class: JsonWebToken

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/jwt_api/templates/initializers/json_web_token.rb

Overview

JSON Web Token class

Instance Method Summary collapse

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