Class: Webhookdb::Service::Auth::Admin

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/service/auth.rb

Overview

Middleware to use for Grape admin auth. See github.com/ruby-grape/grape#register-custom-middleware-for-authentication NOTE: Callers can use auth(nil) to disable auth for specific endpoints.

Instance Method Summary collapse

Constructor Details

#initialize(app, *_args) ⇒ Admin

Returns a new instance of Admin.



59
60
61
# File 'lib/webhookdb/service/auth.rb', line 59

def initialize(app, *_args)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/webhookdb/service/auth.rb', line 63

def call(env)
  return @app.call(env) if Skip.skip?(@app)
  warden = env["warden"]
  customer = warden.authenticate!(scope: :admin)

  unless customer.admin?
    body = Webhookdb::Service.error_body(401, "Unauthorized")
    return 401, {"Content-Type" => "application/json"}, [body.to_json]
  end
  return @app.call(env)
end