Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scope_validator.rb « auth « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de4c36ad594fa6a4138bf57010e48ea3911bf64f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

# Wrapper around a RequestAuthenticator to
# perform authorization of scopes. Access is limited to
# only those methods needed to validate that an API user
# has at least one permitted scope.
module Gitlab
  module Auth
    class ScopeValidator
      def initialize(api_user, request_authenticator)
        @api_user = api_user
        @request_authenticator = request_authenticator
      end

      def valid_for?(permitted)
        return true unless @api_user
        return true if permitted.none?

        scopes = permitted.map { |s| API::Scope.new(s) }
        @request_authenticator.valid_access_token?(scopes: scopes)
      end
    end
  end
end