Class: Rack::IcisIdentityAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/icis_identity_auth.rb

Constant Summary collapse

ROOT_URL =
'http://icis-identity-example.herokuapp.com/api/v1/verify.json'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ IcisIdentityAuth

Returns a new instance of IcisIdentityAuth.



7
8
9
# File 'lib/rack/icis_identity_auth.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
25
26
27
28
29
30
31
32
33
34
# File 'lib/rack/icis_identity_auth.rb', line 11

def call(env)
  token    = env['HTTP_X_BEARER_TOKEN']
  uid      = env['HTTP_X_UID']
  app_name = env['HTTP_X_APP_NAME']

  return forbidden unless token && uid && app_name

  response = HTTParty.get "#{ROOT_URL}?id=#{uid}&token=#{token}&app_name=#{app_name}"

  case response.code
  when 403
    forbidden
  when 404
    error_code(404, 'Not Found')
  when 500
    error_code(500, 'Server Error')
  when 503
    error_code(503, 'Maintenance')
  when 504
    error_code(504, 'System Down')
  end

  @app.call(env)
end