class JwtService

Authentication implementation mostly copied and slightly adapted from paweljw.github.io/2017/07/rails-5.1-api-app-part-4-authentication-and-authorization/ Big thanks!

Public Class Methods

decode(token) click to toggle source
# File natural-backend/app/services/jwt_service.rb, line 10
def self.decode(token)
  body = JWT.decode(token, Rails.application.secrets.secret_key_base,
                     true, algorithm: 'HS256')
  HashWithIndifferentAccess.new(body[0])
rescue JWT::ExpiredSignature
  nil
end
encode(payload) click to toggle source
# File natural-backend/app/services/jwt_service.rb, line 6
def self.encode(payload)
  JWT.encode(payload, Rails.application.secrets.secret_key_base, 'HS256')
end