Sha256: 3dc8045619d51879854ce2401489f7008e5a6487cb2457bbde82a40178235402

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

module Doorkeeper
  module OAuth
    module Helpers
      module ScopeChecker
        class Validator
          attr_reader :parsed_scopes, :scope_str

          def initialize(scope_str, server_scopes, application_scopes)
            @parsed_scopes = OAuth::Scopes.from_string(scope_str)
            @scope_str = scope_str
            @valid_scopes = valid_scopes(server_scopes, application_scopes)
          end

          def valid?
            scope_str.present? &&
              scope_str !~ /[\n|\r|\t]/ &&
              @valid_scopes.has_scopes?(parsed_scopes)
          end

          def match?
            valid? && parsed_scopes.has_scopes?(@valid_scopes)
          end

          private

          def valid_scopes(server_scopes, application_scopes)
            if application_scopes.present?
              server_scopes & application_scopes
            else
              server_scopes
            end
          end
        end

        def self.valid?(scope_str, server_scopes, application_scopes = nil)
          Validator.new(scope_str, server_scopes, application_scopes).valid?
        end

        def self.match?(scope_str, server_scopes, application_scopes = nil)
          Validator.new(scope_str, server_scopes, application_scopes).match?
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
doorkeeper-2.2.2 lib/doorkeeper/oauth/helpers/scope_checker.rb
doorkeeper-3.0.0.rc1 lib/doorkeeper/oauth/helpers/scope_checker.rb
doorkeeper-2.2.1 lib/doorkeeper/oauth/helpers/scope_checker.rb
doorkeeper-2.2.0 lib/doorkeeper/oauth/helpers/scope_checker.rb
doorkeeper-2.1.4 lib/doorkeeper/oauth/helpers/scope_checker.rb
doorkeeper-2.1.3 lib/doorkeeper/oauth/helpers/scope_checker.rb