Class: Gitlab::Auth::ScopeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/auth/scope_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_user, request_authenticator) ⇒ ScopeValidator

Returns a new instance of ScopeValidator.


10
11
12
13
# File 'lib/gitlab/auth/scope_validator.rb', line 10

def initialize(api_user, request_authenticator)
  @api_user = api_user
  @request_authenticator = request_authenticator
end

Instance Method Details

#valid_for?(permitted) ⇒ Boolean

Returns:

  • (Boolean)

15
16
17
18
19
20
21
# File 'lib/gitlab/auth/scope_validator.rb', line 15

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