Class: OAuth2::Rack::Authentication::Client::RequestParams

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/rack/authentication/client/request_params.rb

Overview

2.4.1. Client Password Send client_id and client_secret in request params

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}, &authenticator) ⇒ RequestParams



6
7
8
9
10
11
# File 'lib/oauth2/rack/authentication/client/request_params.rb', line 6

def initialize(app, opts = {}, &authenticator)
  @app = app
  @required = opts.fetch(:required, true)
  opts.delete(:required)
  @authenticator = authenticator || opts.delete(:authenticator)
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oauth2/rack/authentication/client/request_params.rb', line 13

def call(env)
  return @app.call(env) if env.has_key?('oauth2.client')

  @request = Rack::Request.new(env)

  client_id = @request['client_id']
  client_secret = @request['client_secret']
  if client_id.nil? && client_secret.nil?
    return @required ? unauthorized : @app.call(env)
  elsif client_id.nil? || client_secret.nil?
    return bad_request
  end

  client = @authenticator.call(:client_id => client_id, :client_secret => client_secret)
  if client
    env['oauth2.client'] = client
    @app.call(env)
  else
    unauthorized
  end
end