-
Notifications
You must be signed in to change notification settings - Fork 117
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
validate function is called with the wrong number of arguments #446
Comments
Fixed in v7.1.4 |
@kamilmysliwiec I think that it would be better to revert that For example, with incremented length, instead of async validate (accessToken: string, refreshToken: string, profile: any, done: VerifyCallback) {
...
done(null, user);
...
} it will be better to use async validate (accessToken: string, refreshToken: string, profile: any) {
...
return user;
...
} |
@egormkn it seems that explicitly setting the |
Perhaps it will be possible to include this change to the next major update of nestjs/passport, so existing codebases with passport ^7.x.x that execute |
Anyone who wants to use less popular strategies that are not compatible with constructor(...options) {
super(...options);
passport.use(this);
} |
I'm submitting a...
Current behavior
When running @nestjs/passport in version 7.1.x I encountered an issue when using any passport library that relies on passport-oauth2 (in my case passport-google-oauth20@2.0.0 and passport-github-2@0.1.12). It looks like the number of arguments added to my validate does not match the number of returned values.
async validate (accessToken: string, refreshToken: string, profile: any, done: VerifyCallback) {...}
will get me the result that I would expect when writingasync validate (accessToken: string, refreshToken: string, params: any, profile: any, done: VerifyCallback) {...}
. So thedone
param actually holds theprofile
data. Because of that calling the done callback at the end will fail, obviously.After some investigations it looks like that the length of the params passed to the passport library is wrong. Taking a look at https://github.com/nestjs/passport/blob/master/lib/passport/passport.strategy.ts I realized that in line 31 you increase the number of the callbacks arguments by one. So if I provided 4 params in my validate function the passport lib will than assume that the function has 5 arguments and act accordingly.
Using @nestjs/passport@7.0.0 fixes the problem.
Expected behavior
The number of arguments of my validate function should match the number of returned values.
Minimal reproduction of the problem with instructions
I basically followed this example from scratch: https://dev.to/imichaelowolabi/how-to-implement-login-with-google-in-nest-js-2aoa
Environment
The text was updated successfully, but these errors were encountered: