如何在google登录url中发送查询参数并在回调方法中使用



我在我的项目中使用谷歌身份验证。我想在击中google认证的URL中发送查询参数并在被callbackurl击中的回调方法中使用那个参数。这是一个NEST-JS应用程序。

控制器

@Get('google/login')
@UseGuards(GoogleAuthGaurd)
handleGoogleLogin() {}
@Get('google/redirect')
@UseGuards(GoogleAuthGaurd)
async handleGoogleRedirect(@Req() req, @Res() res: Response) {
const tokens = await this.authService.signInWithGoogle(req);
res.redirect(
302,localhost:8080?tokens=token);
}

谷歌警卫队

@Injectable()
export class GoogleAuthGaurd extends AuthGuard('google') {}

策略
export class GoogleStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
clientID: configService.get(ConfigEnum.CLIENT_ID),
clientSecret: configService.get(ConfigEnum.CLIENT_SECRET),
callbackURL: configService.get('CALLBACK_URL'),
scope: ['profile', 'email'],
});
}
async validate(
accessToken: string,
refreshToken: string,
profile: Profile,
done: VerifiedCallback,
): Promise<any> {
const email = profile.emails[0].value;
done(null, email);
}
}

我试图在handleGoogleLogin方法中获取查询参数但它直接进入了策略类

我设法使用ExecutionContext在守卫中添加查询参数。它可以工作,但没有出现在回调url中。

最新更新