Class: Rack::Jwt::Auth::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/jwt/auth/authenticate.rb

Constant Summary collapse

DECODE_OPTIONS =
Set.new([:algorithm,
:verify_expiration,
:verify_not_before,
:verify_iss,
:iss,
:verify_iat,
:verify_aud,
:aud,
:verify_sub,
:sub,
:verify_jti,
:jti]).freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Authenticate

Returns a new instance of Authenticate.



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

def initialize(app, opts = {})
  @app  = app
  @opts = opts

  raise 'Secret must be provided' if opts[:secret].nil?

  # @see https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
  # @see https://github.com/jwt/ruby-jwt/pull/184
  raise 'Algorithm must be provided for security reason' if opts[:algorithm].nil?

  @secret = opts[:secret]

  @authenticated_routes   = compile_paths(opts[:only])
  @unauthenticated_routes = compile_paths(opts[:except])
end

Instance Method Details

#call(env) ⇒ Object



36
37
38
39
40
41
# File 'lib/rack/jwt/auth/authenticate.rb', line 36

def call(env)
  with_authorization(env) do |payload|
    env['rack.jwt.session'] = payload
    @app.call(env)
  end
end