Class: Devise::Strategies::Oauth2GrantTypeStrategy

Inherits:
Authenticatable
  • Object
show all
Defined in:
lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 23

def authenticate!
  client_id, client_secret = request.authorization ? decode_credentials : [params[:client_id], params[:client_secret]]
  client = Devise::Oauth2Providable::Client.find_by_identifier client_id
  if client && client.secret == client_secret
    env[Devise::Oauth2Providable::CLIENT_ENV_REF] = client
    authenticate_grant_type(client)
  else
    oauth_error! :invalid_client
  end
end

#authenticate_grant_type(client) ⇒ Object

defined by subclass



20
21
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 20

def authenticate_grant_type(client)
end

#grant_typeObject

defined by subclass



16
17
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 16

def grant_type
end

#oauth_error!(error_code = :invalid_request, description = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 34

def oauth_error!(error_code = :invalid_request, description = nil)
  body = {:error => error_code}
  description = I18n.t("devise.failure.#{error_code}") unless description
  body[:error_description] = description if description
  custom! [400, {'Content-Type' => 'application/json'}, [body.to_json]]
  throw :warden
end

#store?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 7

def store?
  false
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb', line 11

def valid?
  params[:controller] == 'devise/oauth2_providable/tokens' && request.post? && params[:grant_type] == grant_type
end