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

Sent response body cannot be easily accessible in continuing middlewares #87

Open
esteban-filardi opened this issue Mar 6, 2020 · 2 comments

Comments

@esteban-filardi
Copy link

esteban-filardi commented Mar 6, 2020

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 esteban-filardi changed the title Sent response body cannot be easily be accessible in continuing middlewares Sent response body cannot be easily accessible in continuing middlewares Mar 6, 2020
@AakashPat
Copy link

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?

@nkanand4
Copy link

@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

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

3 participants