Sha256: 0f8bb9ea2f257c36cd0fb0dd9c856b4d272cf6018622fac692810325fb348701

Contents?: true

Size: 943 Bytes

Versions: 5

Compression:

Stored size: 943 Bytes

Contents

require 'devise/oauth2_providable/strategies/oauth2_grant_type_strategy'

module Devise
  module Strategies
    class Oauth2PasswordGrantTypeStrategy < Oauth2GrantTypeStrategy
      def grant_type
        'password'
      end

      def authenticate_grant_type(client)
        keys = mapping.to.authentication_keys
        resource = mapping.to.find_for_database_authentication(keys.first => params[:username])
        if validate(resource) { resource.valid_password?(params[:password]) }
          success! resource
        else
          keys_string = keys.join(I18n.translate(:"support.array.words_connector"))
          message = resource ? resource.unauthenticated_message : :invalid
          oauth_error! :invalid_grant, I18n.t("devise.failure.#{message}", authentication_keys: keys_string)
        end
      end
    end
  end
end

Warden::Strategies.add(:oauth2_password_grantable, Devise::Strategies::Oauth2PasswordGrantTypeStrategy)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
brycesch-devise_oauth2_providable-1.2.8 lib/devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy.rb
brycesch-devise_oauth2_providable-1.2.7 lib/devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy.rb
brycesch-devise_oauth2_providable-1.2.6 lib/devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy.rb
brycesch-devise_oauth2_providable-1.2.5 lib/devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy.rb
brycesch-devise_oauth2_providable-1.2.4 lib/devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy.rb