How to use the restify.NotAuthorizedError function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pcimino / nodejs-restify-mongodb / config / routes-auth.js View on Github external
User.findOne(queryObj, function (err, user) {
            if (err) {
              res.send(err);
              return next();
            } else if (!user) {
              return next(new restify.NotAuthorizedError("Invalid username."));
            } else if (user.authenticate(req.params.password)) {
              if (!user.emailValidatedFlag && !user.newEmail) {
                // user account has never been validated
                return next(new restify.NotAuthorizedError("Email address must be validated to activate your account."));
              } else {
                gUser = user;
                return next();
              }
            } else {
              return next(new restify.NotAuthorizedError("Invalid password."));
            }
          });
      } else {
github pcimino / nodejs-restify-mongodb / config / routes-auth.js View on Github external
if (err.message) {
                    errObj = err.message;
                  } else {
                    errObj = err.err;
                  }
                  return next(new restify.InternalError(errObj));
            } else {
              // clean up all verification codes
              VerifyCode.remove({userObjectId: user._id}, function(err){});

              res.send(successMsg);
              return next();
            }
          });
        } else {
          return next(new restify.NotAuthorizedError(VERIFY_FAIL));
        }
      });
   }
github pcimino / nodejs-restify-mongodb / config / routes-user-signup.js View on Github external
User.findOne(queryObj, function (err, user) {
             if (err) {
                res.send(err);
               return next();
             } else if (!user) {
                return next(new restify.NotAuthorizedError("Invalid username."));
             } else {
               user.password = newPass;
               user.tempPasswordFlag = true;
               user.save(function (err, user) {
                 if (!err) {
                   // send the new password
                   var refer = req.toString().substring(req.toString().indexOf('referer:')+8).trim();
                   var protocol = refer.substring(0, refer.indexOf('//') + 2);
                   var referHost = refer.substring(refer.indexOf('//') + 2);

                   referHost = referHost.substring(0, referHost.indexOf('/'));
                   var fullURL = protocol + referHost;
                   var messageBody = "Hello " + user.name + ",<br><p>Here is your new password. Please login and change it.</p><p>" + newPass + "</p>";
                   messageBody = messageBody + "<a href="&quot; + fullURL + &quot;">Login to your account</a>";

                   var mailAddress = user.email;
github sensebox / openSenseMap-API / lib / requestUtils.js View on Github external
const preRequest = function preRequest (request, response, next) {
  response.charSet('utf-8');
  request.log.info({ req: request }, 'REQUEST');

  if (process.env.ENV === 'prod'
    && (!request.headers['x-forwarded-proto'] || request.headers['x-forwarded-proto'] !== 'https')) {
    if (request.method !== 'POST' || !validUnsecuredPathRegex.test(request.url)) {
      return next(new restify.NotAuthorizedError('Access through http is not allowed'));
    }
  }

  return next();
};
github jedrichards / portfolio / api / api / api.js View on Github external
function handleUnauthorisedAccessError (req,res,next) {
        next(new restify.NotAuthorizedError("Not authorised to access this resource."));
    }
github gustavohenrique / gh1 / server / nodejs / src / services / UserService.js View on Github external
.then(function (user) {
                if (! user) {
                    next(new restify.NotAuthorizedError('email not found'));
                }
                if (user.isHashPasswordEqualsTo(password)) {
                    req.user = {
                        id: user.id,
                        email: user.email
                    };
                    next();
                }
                else {
                    next(new restify.NotAuthorizedError('wrong password'));
                }
            })
            .catch(function (err) {
github joyent / sdc-adminui / lib / auth.js View on Github external
Auth.requireAuth = function requireAuth(req, res, next) {
    if (typeof (req.headers[AUTH_TOKEN_HEADER]) === 'undefined') {
        return next(new restify.NotAuthorizedError(
            util.format('%s not present', AUTH_TOKEN_HEADER)));
    }

    if (!req.sessions) {
        return next(new restify.ServiceUnavailableError('service unavailable (moray)'));
    }

    var token = req.headers[AUTH_TOKEN_HEADER];

    req.sessions.get(token, function (err, data) {
        if (err) {
            err.message = err.message || '';
            return next(new restify.NotAuthorizedError(err.message));
        }

        if (data === null) {
github joyent / sdc-adminui / lib / auth.js View on Github external
req.sessions.get(token, function (err, data) {
        if (err) {
            err.message = err.message || '';
            return next(new restify.NotAuthorizedError(err.message));
        }

        if (data === null) {
            return next(new restify.NotAuthorizedError('Invalid Auth Token'));
        }

        req.sessions.touch(token);
        req.session = {data: data, token: token};
        return next();
    });
github joyent / sdc-adminui / lib / auth.js View on Github external
req.sessions.get(token, function (err, data) {
        if (err) {
            err.message = err.message || '';
            return next(new restify.NotAuthorizedError(err.message));
        }

        if (data === null) {
            return next(new restify.NotAuthorizedError('Invalid Auth Token'));
        }

        req.sessions.touch(token);
        req.session = {data: data, token: token};
        return next();
    });
github gustavohenrique / gh1 / server / nodejs / src / services / UserService.js View on Github external
.then(function (user) {
                if (! user) {
                    next(new restify.NotAuthorizedError('email not found'));
                }
                if (user.isHashPasswordEqualsTo(password)) {
                    req.user = {
                        id: user.id,
                        email: user.email
                    };
                    next();
                }
                else {
                    next(new restify.NotAuthorizedError('wrong password'));
                }
            })
            .catch(function (err) {