function checkScopes(requiredScopes) {
  return function(req, res, next) {
    let authorized = true;
    if (req.scopes) {
      for (let j = 0; j < requiredScopes.length && authorized; j++) {
        if (req.scopes.indexOf(requiredScopes[j]) === -1) {
          authorized = false;
        }
      }
    }
    if (authorized) {
      return next();
    }
    const err = new Error();
    err.status = 401;
    err.message = 'You don\'t have access to the requested resource';
    return next(err);
  };
}
/**
 * Factory of middleware functions that check whether a user has the scopes
 * required to access the required resource. Functions generated by this
 * method must be chained after ensureAuthenticated.
 *
 * @param {array} requiredScopes - An array of strings with the required scopes
 */
Factory of middleware functions that check whether a user has the scopes
required to access the required resource. Functions generated by this
method must be chained after ensureAuthenticated.

@param {array} requiredScopes - An array of strings with the required scopes
Factory of middleware functions that check whether a user has the scopes required to access the required resource . Functions generated by this method must be chained after ensureAuthenticated . @param { array } requiredScopes - An array of strings with the required scopes
function checkScopes(requiredScopes) {
  return function(req, res, next) {
    let authorized = true;
    if (req.scopes) {
      for (let j = 0; j < requiredScopes.length && authorized; j++) {
        if (req.scopes.indexOf(requiredScopes[j]) === -1) {
          authorized = false;
        }
      }
    }
    if (authorized) {
      return next();
    }
    const err = new Error();
    err.status = 401;
    err.message = 'You don\'t have access to the requested resource';
    return next(err);
  };
}
function checkScopes ( requiredScopes ) { return function ( req , res , next ) { let authorized = true ; if ( req . scopes ) { for ( let j = 0 ; j < requiredScopes . length && authorized ; j ++ ) { if ( req . scopes . indexOf ( requiredScopes [ j ] ) === - 1 ) { authorized = false ; } } } if ( authorized ) { return next ( ) ; } const err = new Error ( ) ; err . status = 401 ; err . message = 'You don\'t have access to the requested resource' ; return next ( err ) ; } ; }
Factory of middleware functions that check whether a user has the scopes
 required to access the required resource.
Factory of middleware functions that check whether a user has the scopes required to access the required resource .