module JwtAuthToken
Public Instance Methods
is_jwt_valid_token?()
click to toggle source
# File lib/jwt_auth_token.rb, line 36 def is_jwt_valid_token? begin @decoded_token = JWT.decode(jwt_header_token, jwt_hmac_secret, true, { :algorithm => jwt_algorithm })[0] return validate_keys rescue Exception => e return false end end
jwt_algorithm()
click to toggle source
# File lib/jwt_auth_token.rb, line 9 def jwt_algorithm @_jwt_algorithm ||= 'HS512' end
jwt_header_name()
click to toggle source
# File lib/jwt_auth_token.rb, line 18 def jwt_header_name @_jwt_header_name ||= "embibe-token" end
jwt_header_token()
click to toggle source
# File lib/jwt_auth_token.rb, line 32 def jwt_header_token @_jwt_header_token ||= request.cookies[jwt_cookie_name] || request.headers[jwt_header_name] rescue nil end
jwt_hmac_secret()
click to toggle source
# File lib/jwt_auth_token.rb, line 5 def jwt_hmac_secret @_jwt_hmac_secret ||= Rails.application.secrets[:secret_key_base] end
jwt_set_header(data)
click to toggle source
# File lib/jwt_auth_token.rb, line 13 def jwt_set_header(data) encoded_token = JWT.encode(data,jwt_hmac_secret,jwt_algorithm) response.set_header(jwt_header_name, encoded_token) end
validate_keys()
click to toggle source
# File lib/jwt_auth_token.rb, line 45 def validate_keys !!@_validate_keys ||= (@decoded_token.keys & ["id", "email"]).any? end