auth0-extensions/auth0-delegated-administration-extension

View on GitHub
server/lib/middlewares/requireScope.js

Summary

Maintainability
A
0 mins
Test Coverage
import { ForbiddenError } from 'auth0-extension-tools';

export default (expectedScope) => (req, res, next) => {
  if (!req.user || !req.user.scope || req.user.scope.indexOf(expectedScope) < 0) {
    return next(new ForbiddenError(`Cannot perform action. Missing scope ${expectedScope}`));
  }

  return next();
};