Class: Warden::OAuth2::Strategies::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/warden/oauth2/strategies/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#store?

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/warden/oauth2/strategies/client.rb', line 8

def client
  @client
end

#client_idObject (readonly)

Returns the value of attribute client_id.



8
9
10
# File 'lib/warden/oauth2/strategies/client.rb', line 8

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



8
9
10
# File 'lib/warden/oauth2/strategies/client.rb', line 8

def client_secret
  @client_secret
end

Instance Method Details

#authenticate!Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/warden/oauth2/strategies/client.rb', line 10

def authenticate!
  @client = client_from_http_basic || client_from_request_params

  if self.client
    fail "insufficient_scope" and return if scope && client.respond_to?(:scope) && !client.scope?(scope)
    success! self.client
  else
    fail "invalid_client"
  end
end

#client_from_http_basicObject



21
22
23
24
25
# File 'lib/warden/oauth2/strategies/client.rb', line 21

def client_from_http_basic
  return nil unless (env.keys & Rack::Auth::AbstractRequest::AUTHORIZATION_KEYS).any?
  @client_id, @client_secret = *Rack::Auth::Basic::Request.new(env).credentials
  Warden::OAuth2.config.client_model.locate(self.client_id, self.client_secret)
end

#client_from_request_paramsObject



27
28
29
30
31
# File 'lib/warden/oauth2/strategies/client.rb', line 27

def client_from_request_params
  @client_id, @client_secret = params[:client_id], params[:client_secret]
  return nil unless self.client_id
  Warden::OAuth2.config.client_model.locate(@client_id, @client_secret)
end

#error_statusObject



37
38
39
40
41
42
43
# File 'lib/warden/oauth2/strategies/client.rb', line 37

def error_status
  case message
    when "invalid_client" then 401
    when "insufficient_scope" then 403
    else 400
  end
end

#public_client?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/warden/oauth2/strategies/client.rb', line 33

def public_client?
  client && !client_secret
end