express-oauth-server icon indicating copy to clipboard operation
express-oauth-server copied to clipboard

Sent response body cannot be easily accessible in continuing middlewares

Open esteban-filardi opened this issue 4 years ago • 2 comments

The requirement for my app is the following:

"Log all incoming requests (including the request's response body)".

Even if there is the option continueMiddleware to continue executing a following middleware, it isn't possible to access the response of the token() method in that next middleware. Because of that, I can't easily log the response of the API method to obtain a token.

Maybe it would be feasible to store the response body inside the res object before send it in order to be able to have access it in the following middlewares of the chain.

Alternatively, an option could be added to just obtaining the response body of oauth-node-server but not sending it over automatically.

esteban-filardi avatar Mar 06 '20 20:03 esteban-filardi

I am looking for something similar. The token() method returns an error in the following format in case a wrong set of credentials is used. { "error": "invalid_grant", "error_description": "Invalid grant: user credentials are invalid" }

What I intend to do is to return an appropriate error_description depending on the reason for grant failure. Example: User account does not exist. User account is not verified. Incorrect password.

Does anyone have any idea of how I could achieve this?

AakashPat avatar May 16 '20 18:05 AakashPat

@esteban-filardi you can access response of the token() method by accessing it from the response which will be available to you in the next handler, res.locals.oauth.token. Refer https://github.com/oauthjs/express-oauth-server/blob/master/index.js#L116

nkanand4 avatar Aug 28 '20 15:08 nkanand4