class Rack::PrxAuth

Constants

DEFAULT_ISS
INVALID_TOKEN

Attributes

issuer[R]

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/rack/prx_auth.rb, line 18
def initialize(app, options = {})
  @app = app
  @certificate = Certificate.new(options[:cert_location])
  @issuer = options[:issuer] || DEFAULT_ISS
end

Public Instance Methods

build_auth_validator(token) click to toggle source
# File lib/rack/prx_auth.rb, line 24
def build_auth_validator(token)
  AuthValidator.new(token, @certificate, @issuer)
end
call(env) click to toggle source
# File lib/rack/prx_auth.rb, line 28
def call(env)
  return @app.call(env) unless env['HTTP_AUTHORIZATION']

  token = env['HTTP_AUTHORIZATION'].split[1]

  auth_validator = build_auth_validator(token)

  return @app.call(env) unless should_validate_token?(auth_validator)

  if auth_validator.valid?
    env['prx.auth'] = TokenData.new(auth_validator.claims)
    @app.call(env)
  else
    INVALID_TOKEN
  end
end

Private Instance Methods

should_validate_token?(auth_validator) click to toggle source
# File lib/rack/prx_auth.rb, line 47
def should_validate_token?(auth_validator)
  auth_validator.token_issuer_matches?
end