Class: Zaikio::JWTAuth::RackMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/zaikio/jwt_auth/rack_middleware.rb

Constant Summary collapse

AUDIENCE =
"zaikio.jwt.audience".freeze
SUBJECT =
"zaikio.jwt.subject".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackMiddleware

Returns a new instance of RackMiddleware.



7
8
9
# File 'lib/zaikio/jwt_auth/rack_middleware.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zaikio/jwt_auth/rack_middleware.rb', line 11

def call(env)
  token_data = begin
    Zaikio::JWTAuth.extract(env["HTTP_AUTHORIZATION"])
  rescue JWT::ExpiredSignature, JWT::DecodeError
    nil
  end

  if token_data
    env[AUDIENCE] = token_data.audience || :personal_token
    env[SUBJECT] = token_data.subject
  end

  @app.call(env)
end