class Doorkeeper::OAuth::Helpers::ScopeChecker::Validator

Attributes

parsed_scopes[R]
scope_str[R]

Public Class Methods

new(scope_str, server_scopes, app_scopes, grant_type) click to toggle source
# File lib/doorkeeper/oauth/helpers/scope_checker.rb, line 10
def initialize(scope_str, server_scopes, app_scopes, grant_type)
  @parsed_scopes = OAuth::Scopes.from_string(scope_str)
  @scope_str = scope_str
  @valid_scopes = valid_scopes(server_scopes, app_scopes)

  @scopes_by_grant_type = Doorkeeper.config.scopes_by_grant_type[grant_type.to_sym] if grant_type
end

Public Instance Methods

valid?() click to toggle source
# File lib/doorkeeper/oauth/helpers/scope_checker.rb, line 18
def valid?
  scope_str.present? &&
    scope_str !~ /[\n\r\t]/ &&
    @valid_scopes.has_scopes?(parsed_scopes) &&
    permitted_to_grant_type?
end

Private Instance Methods

permitted_to_grant_type?() click to toggle source
# File lib/doorkeeper/oauth/helpers/scope_checker.rb, line 31
def permitted_to_grant_type?
  return true unless @scopes_by_grant_type

  OAuth::Scopes.from_array(@scopes_by_grant_type)
    .has_scopes?(parsed_scopes)
end
valid_scopes(server_scopes, app_scopes) click to toggle source
# File lib/doorkeeper/oauth/helpers/scope_checker.rb, line 27
def valid_scopes(server_scopes, app_scopes)
  app_scopes.presence || server_scopes
end