rkusa/koa-passport

Extend req/res mock to include send()

TigerC10 opened this issue ยท 4 comments

Some of the passport strategies out there use req.res.send() to achieve a redirect via automatic post (for example: passport-saml).

In order to support this, koa-passport should mock out the send() function as well as make the res mock available on the req mock.

rkusa commented

Hi, do you now whether req.res is set by those strategies or whether it is part of Express? Totally agree on the send() function.

req.res is definitely not set by those strategies. I've inadvertently used it in express projects myself in non-passport projects before I learned how res should more properly be accessed. While learning express, console.dir(req) showed me that I had a req.res and I used it instead of just adding res to the middleware function's parameters. Thankfully I've learned not to do that anymore!

Passport kind of forces these strategies to go through req in this non-ideal way:

https://github.com/jaredhanson/passport-strategy/blob/497a45324538e8e9967e2e27fbde6f3b6860f216/lib/strategy.js#L20

Passport doesn't expose res to strategies separately. ๐Ÿ˜•

rkusa commented

Thanks for elaborating! It should definitely be added to koa-passport ๐Ÿ™‚

Thanks for merging and releasing the new version so quickly! ๐Ÿ˜„