Class: AuthenticJwt::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/authentic_jwt/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(public_key: ENV["AUTHENTIC_AUTH_PUBLIC_KEY"]) ⇒ Validator

Returns a new instance of Validator.



6
7
8
9
10
11
12
# File 'lib/authentic_jwt/validator.rb', line 6

def initialize(public_key: ENV["AUTHENTIC_AUTH_PUBLIC_KEY"])
  if public_key.to_s.empty?
    raise Unauthorized, "JWT public key not present"
  end

  @public_key = OpenSSL::PKey::RSA.new(public_key.to_s)
end

Instance Method Details

#call(header:) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/authentic_jwt/validator.rb', line 14

def call(header:)
  if header.to_s.empty?
    raise Unauthorized, "Authorization header missing"
  end

  bearer_token = extract_bearer_token(header: header)

  extract_payload(bearer_token: bearer_token)
end