Class: Authify::Middleware::JWTAuth

Inherits:
Object
  • Object
show all
Includes:
Core::Helpers::JWTSSL
Defined in:
lib/authify/middleware/jwt_auth.rb

Overview

Auth Middleware

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ JWTAuth

Returns a new instance of JWTAuth.



7
8
9
# File 'lib/authify/middleware/jwt_auth.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/authify/middleware/jwt_auth.rb', line 13

def call(env)
  begin
    payload = process_token(env)

    env[:scopes] = payload['scopes']
    env[:user] = payload['user']
    env[:authenticated] = Time.now
  rescue JWT::DecodeError => e
    env[:authenticated] = false
    env[:authentication_errors] ||= []
    env[:authentication_errors] << e
  rescue JWT::ExpiredSignature => e
    env[:authenticated] = false
    env[:authentication_errors] ||= []
    env[:authentication_errors] << e
  rescue JWT::InvalidIssuerError => e
    env[:authenticated] = false
    env[:authentication_errors] ||= []
    env[:authentication_errors] << e
  rescue JWT::InvalidIatError => e
    env[:authenticated] = false
    env[:authentication_errors] ||= []
    env[:authentication_errors] << e
  end
  @app.call env
end