Class: Warden::OAuth2::FailureApp

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/oauth2/failure_app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(env) ⇒ Object



5
6
7
# File 'lib/warden/oauth2/failure_app.rb', line 5

def self.call(env)
  new.call(env)
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/warden/oauth2/failure_app.rb', line 9

def call(env)
  warden = env['warden']
  strategy = warden.winning_strategy

  headers = {'Content-Type' => 'application/json'}
  body = {}
  if strategy
    error_description = strategy.respond_to?(:error_description) ? strategy.error_description : ''
    body[:error] = strategy.message
    body[:error_description] = error_description
    status = strategy.error_status

    headers['X-Accepted-OAuth-Scopes'] = (strategy.scope || :public).to_s
  else
    status = 400
    body[:error] = 'invalid_request'
    body[:error_description] = 'cannot determine authentication method'
  end
  [status, headers, [JSON.dump(body)]]
end