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

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

Instance Attribute Summary collapse

Attributes inherited from Base

#error_description

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 'invalid_scope' and return if scope && client.respond_to?(:scope) && !client.scope?(scope)
    client_authenticated
  else
    fail 'invalid_client'
  end
end

#client_authenticatedObject



49
50
51
# File 'lib/warden/oauth2/strategies/client.rb', line 49

def client_authenticated
  success! self.client
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
  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
  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', 'invalid_token' then 401
    when 'invalid_scope' then 403
    else 400
  end
end

#modelObject



45
46
47
# File 'lib/warden/oauth2/strategies/client.rb', line 45

def model
  raise 'Model should be defined in a child strategy'
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