Sha256: d6d1ed94ce3dcfe8d374beb02b5082048a5e782131fac0fbb13d8f8b24b5527f

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Doorkeeper
  module OAuth
    class PasswordAccessTokenRequest < BaseRequest
      include OAuth::Helpers

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

      attr_accessor :server, :client, :resource_owner, :parameters,
                    :access_token

      def initialize(server, client, resource_owner, parameters = {})
        @server          = server
        @resource_owner  = resource_owner
        @client          = client
        @parameters      = parameters
        @original_scopes = parameters[:scope]
      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
        !parameters[:client_id] || !!client
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-4.2.6 lib/doorkeeper/oauth/password_access_token_request.rb
doorkeeper-4.2.5 lib/doorkeeper/oauth/password_access_token_request.rb