Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token middleware does not call application server's "next" #216

Open
Earthstar opened this issue Sep 7, 2017 · 1 comment
Open

Token middleware does not call application server's "next" #216

Earthstar opened this issue Sep 7, 2017 · 1 comment

Comments

@Earthstar
Copy link

I'm using oauth2orize v1.0.1 with restify. The server is configured to use the token middleware as such:

var oauth2orize = require('oauth2orize');
var oauth2Server = oauth2orize.createServer();

server.post('/oauth/token',
      passport.authenticate('oauth2-client-password', { session: false }),
      oauth2Server.token(),
      oauth2Server.errorHandler()
);

The server is also configured to log after the server has finished processing a response.

server.on('after', function(req, res) {
    var responseLog = {
        type: 'response',
            method: req.method,
            path: req.path(),
            route: req.route && req.route.path
        };

    req.log.info(responseLog);
});

However, the logging code is not executed after /oauth/token requests. This is because the token middleware doesn't call restify's "next" method unless there's an error. You can see this if you add an additional middleware after oauth2Server.token().

var oauth2orize = require('oauth2orize');
var oauth2Server = oauth2orize.createServer();

server.post('/oauth/token',
      passport.authenticate('oauth2-client-password', { session: false }),
      oauth2Server.token(),
      function(req, res, next) {
            console.log('after token middleware'); // this doesn't get executed
            next();
      }
      oauth2Server.errorHandler()
);

I believe the token middleware should always call restify's "next" regardless of whether there's an error.

@0x1Roshan
Copy link

@Earthstar @jaredhanson its because the response is end in clientCredentials.js file issued method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants