Check if the requested scopes are covered by authorized scopes
@param {String|String[]) requestedScopes
@param {String|String[]) authorizedScopes
@returns {boolean}
554605
function isScopeAuthorized(requestedScopes, authorizedScopes) {
    requestedScopes = normalizeScope(requestedScopes);
    authorizedScopes = normalizeScope(authorizedScopes);
    if (requestedScopes.length === 0) {
        return true;
    }
    for (var i = 0, n = requestedScopes.length; i < n; i++) {
        if (authorizedScopes.indexOf(requestedScopes[i]) === -1) {
            return false;
        }
    }
    return true;
}
282832
def validate_scopes(self, request):
        
        if not request.scopes:
            request.scopes = utils.scope_to_list(request.scope) or utils.scope_to_list(
                self.request_validator.get_default_scopes(request.client_id, request))
        log.debug('Validating access to scopes %r for client %r (%r).',
                  request.scopes, request.client_id, request.client)
        if not self.request_validator.validate_scopes(request.client_id,
                                                      request.scopes, request.client, request):
            raise errors.InvalidScopeError(request=request)
324538
protected function validateTokenScopes(array $scopes)
    {
        $scopes = array_map(function ($scope) {
            return (string) $scope;
        }, $scopes);

        $registeredScopes = $this->scopeService->getAll();

        $registeredScopes = array_map(function ($scope) {
            return (string) $scope;
        }, $registeredScopes);

        $diff = array_diff($scopes, $registeredScopes);

        if (count($diff) > 0) {
            throw OAuth2Exception::invalidScope(sprintf(
                'Some scope(s) do not exist: %s',
                implode(', ', $diff)
            ));
        }
    }
25070
function OauthScopeMethods(models, config) {
      var scope, scopeDefinition, _i, _len, _ref;
      this.models = models;
      this.getScope = __bind(this.getScope, this);
      this.allScopeNamesAsArray = __bind(this.allScopeNamesAsArray, this);
      this.get = __bind(this.get, this);
      this.all = __bind(this.all, this);
      if (config && config.scopes) {
        _ref = config.scopes;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          scopeDefinition = _ref[_i];
          scope = new Scope(scopeDefinition);
          if (scope.isValid()) {
            this.loadedScopes[scope.name] = scope;
          } else {
            console.log("Invalid scope in config - skipped - " + (JSON.stringify(scopeDefinition)));
          }
        }
      }
    }
251953
def get_scopes(self, vpnid='.*'):
        """"""
        request_url = self._build_url(['Scope'], vpn=vpnid)
        return self._do_request('GET', request_url)
351083
public boolean checkAccess(AccessFlags flags){

        boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
        boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
        boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
        boolean isPackage = !(isPublic || isProtected || isPrivate);

        if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
            return false;
        else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
            return false;
        else if ((showAccess == 0) && (isPrivate))
            return false;
        else
            return true;
    }
434658
function isScopeAllowed(allowedScopes, tokenScopes) {
    allowedScopes = normalizeScope(allowedScopes);
    tokenScopes = normalizeScope(tokenScopes);
    if (allowedScopes.length === 0) {
        return true;
    }
    for (var i = 0, n = allowedScopes.length; i < n; i++) {
        if (tokenScopes.indexOf(allowedScopes[i]) !== -1) {
            return true;
        }
    }
    return false;
}
562742
function determineClientScope (req, res, next) {
  var params = req.connectParams
  var subject = req.client
  var scope = params.scope || subject.default_client_scope

  if (params.grant_type === 'client_credentials') {
    Scope.determine(scope, subject, function (err, scope, scopes) {
      if (err) { return next(err) }
      req.scope = scope
      req.scopes = scopes
      next()
    })
  } else {
    next()
  }
}
701154
public function scopeExists($scope, $client_id = null)
    {
        $scopes = explode(' ', $scope);
        if ($client_id) {
            // Get Client
            $client = $this->em->getRepository('OAuth2ServerBundle:Client')->find($client_id);

            if (!$client) {
                return false;
            }

            $valid_scopes = $client->getScopes();

            foreach ($scopes as $scope) {
                if (!in_array($scope, $valid_scopes)) {
                    return false;
                }
            }

            return true;
        }

        $valid_scopes = $this->sm->findScopesByScopes($scopes);

        return count($valid_scopes) == count($scopes);
    }
509740
def _collect_names(handlers, scopes, user, client):
    

    results = set()

    data = {'user': user, 'client': client}

    def visitor(_scope_name, func):
        claim_names = func(data)
        # If the claim_names is None, it means that the scope is not authorized.
        if claim_names is not None:
            results.update(claim_names)

    _visit_handlers(handlers, visitor, 'scope', scopes)

    return results
402944
public function checkScope($scope)
	{
		if (isset($this->scopes[$scope])) {
			return $this->scopes[$scope];
		}
		
		if (!empty($this->scopes['*'])) {
			return true;
		}
		
		if (!$this->check()) {
			return false;
		}
		
		if ('user' == $this->type) {
			$this->scopes[$scope] = Authorizer::hasScope($scope);
		}
		else {
			$client = $this->client();
			$this->scopes[$scope] = in_array($scope, $client->scopes());
		}
		
		if (!$this->scopes[$scope] && '*' != $scope) {
			$this->scopes[$scope] = $this->checkScope('*');
		}
		
		return $this->scopes[$scope];
	}
1124710
function (context, authorisationRequest, callback) {

            try {
                this._isAuthorized(context, authorisationRequest);
                callback();
            } catch (e) {
                callback(e);
            }
        }
1197362
public Maybe<String> getValidScope(String scope, String clientId) {
        return DBManagerFactory.getInstance()
                .findClientCredentials(clientId)
                .map(creds -> getValidScopeByScope(scope, creds.getScope()));
    }
913748
public boolean isAuthorizationRequired(int statusCode, Map<String, List<String>> headers) {

        if (headers.containsKey(WWW_AUTHENTICATE_HEADER_NAME)){
            String authHeader = headers.get(WWW_AUTHENTICATE_HEADER_NAME).get(0);
            return AuthorizationHeaderHelper.isAuthorizationRequired(statusCode, authHeader);
        } else {
            return false;
        }
    }
21912
def protected_resource_view(scopes=None):
    
    if scopes is None:
        scopes = []

    def wrapper(view):
        def view_wrapper(request,  *args, **kwargs):
            access_token = extract_access_token(request)

            try:
                try:
                    kwargs['token'] = Token.objects.get(access_token=access_token)
                except Token.DoesNotExist:
                    logger.debug('[UserInfo] Token does not exist: %s', access_token)
                    raise BearerTokenError('invalid_token')

                if kwargs['token'].has_expired():
                    logger.debug('[UserInfo] Token has expired: %s', access_token)
                    raise BearerTokenError('invalid_token')

                if not set(scopes).issubset(set(kwargs['token'].scope)):
                    logger.debug('[UserInfo] Missing openid scope.')
                    raise BearerTokenError('insufficient_scope')
            except BearerTokenError as error:
                response = HttpResponse(status=error.status)
                response['WWW-Authenticate'] = 'error="{0}", error_description="{1}"'.format(
                    error.code, error.description)
                return response

            return view(request,  *args, **kwargs)

        return view_wrapper

    return wrapper
169353
function loadScopes(scopes) {
  var scopeMapping = {};
  if (typeof scopes === 'object') {
    for (var s in scopes) {
      var routes = [];
      var entries = scopes[s];
      debug('Scope: %s routes: %j', s, entries);
      if (Array.isArray(entries)) {
        for (var j = 0, k = entries.length; j < k; j++) {
          var route = entries[j];
          if (typeof route === 'string') {
            routes.push({methods: ['all'], path: route,
              regexp: pathToRegexp(route, [], {end: false})});
          } else {
            var methods = helpers.normalizeList(methods);
            if (methods.length === 0) {
              methods.push('all');
            }
            methods = methods.map(toLowerCase);
            routes.push({methods: methods,
              path: route.path,
              regexp: pathToRegexp(route.path, [], {end: false})});
          }
        }
      } else {
        debug('Routes must be an array: %j', entries);
      }
      scopeMapping[s] = routes;
    }
  } else if (typeof scopes === 'string') {
    scopes = helpers.normalizeList(scopes);
    for (var i = 0, n = scopes.length; i < n; i++) {
      scopeMapping[scopes[i]] = [
        {methods: 'all', path: '/.+', regexp: /\/.+/}
      ];
    }
  }
  return scopeMapping;
}
139329
def get_visible_scopes(self):
        
        return [k for k, s in current_oauth2server.scope_choices()
                if k in self.scopes]