Sha256: 782e2ff18edf1a1beda70711cf26fd750443d54fb92f42081a31e25adc9ea24e

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    module ClientCredentials
      class Validator
        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
          return if @client.blank?

          Doorkeeper.config.allow_grant_flow_for_client?(
            Doorkeeper::OAuth::CLIENT_CREDENTIALS,
            @client.application,
          )
        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

10 entries across 10 versions & 1 rubygems

Version Path
doorkeeper-5.6.0.rc1 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.4 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.3 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.2 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.1 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.0 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.0.rc2 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.5.0.rc1 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.4.0 lib/doorkeeper/oauth/client_credentials/validator.rb
doorkeeper-5.4.0.rc2 lib/doorkeeper/oauth/client_credentials/validator.rb