Class: OctopusAuth::AccessScopeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/octopus_auth/access_scope_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ AccessScopeValidator

Returns a new instance of AccessScopeValidator.



3
4
5
6
# File 'lib/octopus_auth/access_scope_validator.rb', line 3

def initialize(access_token)
  @access_token = access_token
  @access_scopes = (access_token.access_scopes || '').split(OctopusAuth.configuration.access_scopes_delimiter)
end

Class Method Details

.valid?(access_token, *required_scopes) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/octopus_auth/access_scope_validator.rb', line 12

def self.valid?(access_token, *required_scopes)
  self.new(access_token).valid?(*required_scopes)
end

Instance Method Details

#valid?(*required_scopes) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/octopus_auth/access_scope_validator.rb', line 8

def valid?(*required_scopes)
  access_all_scopes? || required_scopes.any? { |scope| access_scopes.include?(scope.to_s) }
end