Sha256: f2dc26b1f628b2bc18579e01efa046f0a669bc73933185c1e8d57fda88136cfc

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class ClientCredentialsRequest < BaseRequest
      class Validation
        include Validations
        include OAuth::Helpers

        validate :client, error: :invalid_client
        validate :client_supports_grant_flow, error: :unauthorized_client
        validate :scopes, error: :invalid_scope

        def initialize(server, request)
          @server = server
          @request = request
          @client = request.client

          validate
        end

        private

        def validate_client
          @client.present?
        end

        def validate_client_supports_grant_flow
          Doorkeeper.configuration.allow_grant_flow_for_client?(
            Doorkeeper::OAuth::CLIENT_CREDENTIALS,
            @client
          )
        end

        def validate_scopes
          return true if @request.scopes.blank?

          application_scopes = if @client.present?
                                 @client.application.scopes
                               else
                                 ""
                               end

          ScopeChecker.valid?(
            scope_str: @request.scopes.to_s,
            server_scopes: @server.scopes,
            app_scopes: application_scopes,
            grant_type: Doorkeeper::OAuth::CLIENT_CREDENTIALS
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
doorkeeper-5.2.6 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.5 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.4 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.3 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.2 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.1 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.0 lib/doorkeeper/oauth/client_credentials/validation.rb
doorkeeper-5.2.0.rc3 lib/doorkeeper/oauth/client_credentials/validation.rb