Sha256: 43bba7fb80b95cc87dcb89874d9d38fc1817ab4cf870a1abdde7dc7495b2f246

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

module Doorkeeper
  module OAuth
    class PasswordAccessTokenRequest
      include Validations
      include OAuth::RequestConcern
      include OAuth::Helpers

      validate :client,         error: :invalid_client
      validate :resource_owner, error: :invalid_grant
      validate :scopes,         error: :invalid_scope

      attr_accessor :server, :resource_owner, :credentials, :access_token
      attr_accessor :client

      def initialize(server, credentials, resource_owner, parameters = {})
        @server          = server
        @resource_owner  = resource_owner
        @credentials     = credentials
        @original_scopes = parameters[:scope]

        if credentials
          @client = Application.by_uid_and_secret credentials.uid,
                                                  credentials.secret
        end
      end

      private

      def before_successful_response
        find_or_create_access_token(client, resource_owner.id, scopes, server)
      end

      def validate_scopes
        return true unless @original_scopes.present?
        ScopeChecker.valid? @original_scopes, server.scopes, client.try(:scopes)
      end

      def validate_resource_owner
        !!resource_owner
      end

      def validate_client
        !credentials || !!client
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
doorkeeper-3.1.0 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-3.0.1 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.2.2 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-3.0.0 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-3.0.0.rc2 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-3.0.0.rc1 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.2.1 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.2.0 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.1.4 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.1.3 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.1.2 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.1.1 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-2.1.0 lib/doorkeeper/oauth/password_access_token_request.rb