Class: JWT::Authenticator

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/jwt-authenticator/version.rb,
lib/jwt-authenticator.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"2.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuthenticator

Returns a new instance of Authenticator.



15
16
17
18
# File 'lib/jwt-authenticator.rb', line 15

def initialize
  @verification_options = token_verification_options_from_environment \
    self.class.name.split("::")[0...-1].join("_").underscore.upcase.gsub(/_?JWT\z/, "") + "_JWT"
end

Class Method Details

.call(token) ⇒ Object



70
71
72
# File 'lib/jwt-authenticator.rb', line 70

def call(token)
  instance.call(token)
end

Instance Method Details

#call(token) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jwt-authenticator.rb', line 20

def call(token)
  error! type: :token_missing unless token.present?

  returned = JWT.decode token, nil, true, @verification_options do |header|
    public_key(header.deep_symbolize_keys)
  end

  returned.map(&:deep_symbolize_keys)

rescue JWT::ExpiredSignature => e
  error! message: e.inspect, type: :token_expired

rescue JWT::DecodeError => e
  error! message: e.inspect, type: :token_invalid
end