function needsPermission(permission) {
    return function(req,res,next) {
        if (settings && settings.adminAuth) {
            return passport.authenticate(['bearer','tokens','anon'],{ session: false })(req,res,function() {
                if (!req.user) {
                    return next();
                }
                if (permissions.hasPermission(req.authInfo.scope,permission)) {
                    return next();
                }
                log.audit({event: "permission.fail", permissions: permission},req);
                return res.status(401).end();
            });
        } else {
            next();
        }
    }
}
Returns an Express middleware function that ensures the user making a request
has the necessary permission.

@param {String} permission - the permission required for the request, such as `flows.write`
@return {Function} - an Express middleware
@memberof @node-red/editor-api_auth