domenic / restify-oauth2

A simple OAuth 2 endpoint for Restify
Other
294 stars 82 forks source link

Restify v5.x-compatible version? #47

Open alexsk opened 7 years ago

alexsk commented 7 years ago

In Restify v5.x all errors definitions were moved into the separate repository: restify-errors.

As a result, restify-oauth2 code requires refactoring as described here: http://restify.com/docs/home/#restify-errors

billchau commented 7 years ago

For example, the makeOAuthError.js file should be changed to the following.

"use strict";

var errors = require("restify-errors");

module.exports = function makeOAuthError(errorClass, errorType, errorDescription) {
    var body = { error: errorType, error_description: errorDescription };
    return new errors[errorClass + "Error"]({ message: errorDescription, body: body });
};

Moreover, the error response for the secret route in server.js should be the following

if (!req.username) {
    return res.send(new errors.UnauthorizedError("No allowed."));
//not return res.sendUnauthenticated();
}

PS. you need to import the "restify-errors" at the beginning of the file