Class: JWT::Authenticator
- Inherits:
-
Object
- Object
- JWT::Authenticator
- Includes:
- Singleton
- Defined in:
- lib/jwt-authenticator/version.rb,
lib/jwt-authenticator.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"1.0.3"
Class Method Summary collapse
Instance Method Summary collapse
- #call(token) ⇒ Object
-
#initialize ⇒ Authenticator
constructor
A new instance of Authenticator.
Constructor Details
#initialize ⇒ Authenticator
15 16 17 18 |
# File 'lib/jwt-authenticator.rb', line 15 def initialize = \ self.class.name.split("::")[0...-1].join("_").underscore.upcase.gsub(/_?JWT\z/, "") + "_JWT" end |
Class Method Details
.call(token) ⇒ Object
63 64 65 |
# File 'lib/jwt-authenticator.rb', line 63 def call(token) instance.call(token) end |
Instance Method Details
#call(token) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/jwt-authenticator.rb', line 20 def call(token) error! "Token is missing.", 101 if token.blank? token_type, token_value = token.to_s.squish.split(" ") error! "Token type is not provided or invalid.", 102 unless token_type == "Bearer" returned = JWT.decode(token_value, nil, true, ) { |header| public_key(header.deep_symbolize_keys) } returned.map(&:deep_symbolize_keys) rescue JWT::DecodeError => e error!(e.inspect, 103) end |