Sha256: 411e8f84c9b15d76f3a2211a6e0fa03923d4bf44293199e5168199e21e099fb2

Contents?: true

Size: 1.3 KB

Versions: 18

Compression:

Stored size: 1.3 KB

Contents

require 'doorkeeper/oauth/error'
require 'doorkeeper/oauth/error_response'
require 'doorkeeper/oauth/scopes'
require 'doorkeeper/oauth/token_response'
require 'doorkeeper/oauth/client_credentials/creator'
require 'doorkeeper/oauth/client_credentials/issuer'
require 'doorkeeper/oauth/client_credentials/validation'

module Doorkeeper
  module OAuth
    class ClientCredentialsRequest
      attr_accessor :issuer, :server, :client, :original_scopes, :scopes
      attr_reader   :response
      alias         :error_response :response

      delegate :error, :to => :issuer

      def issuer
        @issuer ||= Issuer.new(server, Validation.new(server, self))
      end

      def initialize(server, client, parameters = {})
        @client, @server = client, server
        @response        = nil
        @original_scopes = parameters[:scope]
      end

      def authorize
        status = issuer.create(client, scopes)
        @response = if status
          TokenResponse.new(issuer.token)
        else
          ErrorResponse.from_request(self)
        end
      end

      # TODO: duplicated code in all flows
      def scopes
        @scopes ||= if @original_scopes.present?
          Doorkeeper::OAuth::Scopes.from_string(@original_scopes)
        else
          server.default_scopes
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
doorkeeper-1.1.0 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-1.0.0 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-1.0.0.rc2 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-1.0.0.rc1 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.7.4 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.7.3 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.7.2 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.7.1 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.7.0 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.7 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.6 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.5 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.4 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.3 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.2 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.1 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.0 lib/doorkeeper/oauth/client_credentials_request.rb
doorkeeper-0.6.0.rc1 lib/doorkeeper/oauth/client_credentials_request.rb