lib/matic-jwt/authenticator.rb in matic-jwt-0.2.5 vs lib/matic-jwt/authenticator.rb in matic-jwt-0.3.0
- old
+ new
@@ -1,11 +1,11 @@
module MaticJWT
class Authenticator
TOKEN_TYPE = 'Bearer: '.freeze
- def initialize(headers)
- @token = extract_token(headers)
+ def initialize(header)
+ @token = extract_token(header)
end
def client_name
payload.first['client_name']
end
@@ -14,20 +14,20 @@
JWT.decode(@token, secret, true, algorithm: ALGORITHM)
end
private
- def extract_token(headers)
- header = headers['Authorization']
- validate_header_presence!(header)
- header.slice(TOKEN_TYPE.length..-1)
+ def extract_token(header)
+ token = header.slice(TOKEN_TYPE.length..-1)
+ validate_header_presence!(token)
+ token
end
def payload
JWT.decode(@token, nil, false)
end
- def validate_header_presence!(header)
- raise(JWT::DecodeError, 'Authorization header is missing') if header.nil?
+ def validate_header_presence!(token)
+ raise(JWT::DecodeError, 'Authorization token is incorrect') unless token&.present?
end
end
end