How to use the UnauthorizedError function from restify

Find comprehensive JavaScript restify.UnauthorizedError code examples handpicked from public code repositorys.

44
45
46
47
48
49
50
51
52
}

return employeeQueryService.getEmployeeByUserName(req.user.email).then(function (employee) {

    if (employeeId === employee.id) {
        res.send(new restify.UnauthorizedError());
        next();
        return;
    }
fork icon69
star icon95
watch icon21

147
148
149
150
151
152
153
154
155
156
 * response body (because the `docker` CLI prints that body) and (b) always
 * have that body be "Unauthorized" to not accidentally leak auth details.
 */
function UnauthorizedError(cause) {
    if (cause) {
        restify.UnauthorizedError.call(this, cause, 'Unauthorized');
    } else {
        restify.UnauthorizedError.call(this, 'Unauthorized');
    }
}
fork icon49
star icon182
watch icon65

+ 3 other calls in file

157
158
159
160
161
162
163
164
165
166
                next();
                return;
        }

        response.header('WWW-authenticate', 'Basic realm="kartlytics"');
        next(new mod_restify.UnauthorizedError());
        response.end();
}

/*
fork icon8
star icon77
watch icon12

+ 3 other calls in file

121
122
123
124
125
126
127
128
129
130
router.post('/user/login', async (req, res) => {
  if (!req.params.username || !req.params.password) return res.send(new restify.BadRequestError('Missing username and/or password'));

  const user = await User.findById(req.params.username);
  if (!user) return res.send(new restify.UnauthorizedError('Unauthorized'));
  if (!user.get('verified')) return res.send(new restify.UnauthorizedError('Unauthorized'));

  bcrypt.compare(req.params.password, user.get('password'), (err, match) => {
    if (err) return res.send(new restify.InternalServerError('Internal server error'));
    if (!match) return res.send(new restify.UnauthorizedError('Unauthorized'));
fork icon0
star icon1
watch icon2

+ 5 other calls in file

594
595
596
597
598
599
600
601
602
603
} else if (err.name === 'NotFoundError') {
    // Docker registry client image not found error.
    return new restify.ResourceNotFoundError(err, errMsg);
} else if (err.name === 'UnauthorizedError') {
    // Docker registry client unauthorized error.
    return new restify.UnauthorizedError(err, errMsg);
} else {
    // Unexpected error - wrap it into an internal error.
    return new restify.InternalError(err, errMsg);
}
fork icon17
star icon5
watch icon0

11
12
13
14
15
16
17
18
19
20
 * @description Extract an API key from a request's parsed Authorization header. Emit an error if
 *  no such header is present, or if it's not formed correctly.
 */
var parseAuth = function (auth, callback) {
  if (!auth || !Object.keys(auth).length) {
    return callback(new restify.UnauthorizedError('An API key is required for this endpoint.'));
  }

  if (auth.scheme !== 'deconst') {
    return callback(new restify.InvalidHeaderError('Your Authorization header specifies an incorrect scheme.'));
fork icon9
star icon0
watch icon1

+ 5 other calls in file

6
7
8
9
10
11
12
13
14
15
return function curOrganization(req, res, next) {
  assert.equal(typeof req, 'object', 'req must be an object of group');
  assert.equal(Array.isArray(req.organizations), true, 'req.organization must be an array');

  if (!req.organizations.includes(req.params[param])) {
    throw new restify.UnauthorizedError(`No organization for field ${param}`);
  }

  req.currentOrganization = req.params[param]; // eslint-disable-line no-param-reassign
  return next();
fork icon0
star icon0
watch icon3