Oauth 如何在Nest.js身份验证流期间传递状态

Oauth 如何在Nest.js身份验证流期间传递状态,oauth,passport.js,nestjs,Oauth,Passport.js,Nestjs,在执行GoogleOAuth流时,可以将加密状态(base64)作为参数传递给最终回调。例如,当您希望将用户重定向到特定页面时,这非常有用。() 是否可以将OAuth状态与Nest.js身份验证库一起使用?似乎忽略了state参数,我在文档中找不到任何内容 @Injectable() export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { constructor(readonly configSer

在执行GoogleOAuth流时,可以将加密状态(base64)作为参数传递给最终回调。例如,当您希望将用户重定向到特定页面时,这非常有用。()

是否可以将OAuth状态与Nest.js身份验证库一起使用?似乎忽略了state参数,我在文档中找不到任何内容

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
  constructor(readonly configService: ConfigService) {
    super({
      clientID: configService.get('google.clientId'),
      clientSecret: configService.get('google.clientSecret'),
      callbackURL: `${configService.get('apiUri')}${configService.get('google.callbackUrl')}`,
      passReqToCallback: true,
      scope: ['profile', 'email'],
    });
  }
}

为了解决这个问题,我在设置状态值的类中添加了一个
authenticate
函数

authenticate(req, options) {
  options.state = 'your state value here'
  super.authenticate(req, options)
}

免责声明:我试图实现与您描述的类似的目标,这种方法对我很有效,但我不确定这是否是处理此问题的“正确”方法。

谢谢您的回答!我会等待NestJS的真正解决方案,但这是我们最终要做的工作。