require "jwt_auth/engine" module JwtAuth module Token HMAC_SECRET = 'my$ecretK3y' def self.authorize!(env) return false unless env['HTTP_AUTHORIZATION'] token = env['HTTP_AUTHORIZATION'] begin params = (JWT.decode token, HMAC_SECRET, true, algorithm: 'HS256').first User.find_by(params).present? rescue JWT::DecodeError false end end def self.generate_token(params) JWT.encode params, HMAC_SECRET, 'HS256' end end end