如何将数据从 React Native 传递到 Passport.js FacebookTokenStrategy 回调?

How to Pass Data from React Native to Passport.js FacebookTokenStrategy Callback?

我正在尝试将 deviceID 等数据传递给 Passport.jsFacebookTokenStrategy 回调。

我尝试使用 req._toParam,但它不起作用,似乎已被弃用。

服务器路由器文件

authRouter.post(
    '/facebook/token',
      (req, res, next) => {
        req._toParam = req.user.uniqueDeviceID;
        passport.authenticate('facebook-token')(req, res, next)
      },
      (req, res) => {
        res.send(req.user);
      }
  );

服务器通行证策略文件

passport.use(
    new FacebookTokenStrategy(
        {
            clientID: keys.facebookAppID,
            clientSecret: keys.facebookAppSecret
        },
        async (req, accessToken, refreshToken, profile, done) => {  
                 console.log(req._toParam); 
                 //how to pass react-native-device-info deviceID to this callback?
              }
       )
)

反应本机客户端

const res = await server.post(`/auth/facebook/token?access_token=${tokenData.accessToken}&uniqueDeviceID=${DeviceInfo.getUniqueId()}`);            

如有任何帮助,我们将不胜感激。

我通过在 FacebookTokenStrategy 中添加 passReqToCallback: true 将请求传递给策略回调并使用 req.query 检索查询字符串数据 uniqueDeviceID=${DeviceInfo.getUniqueId()}.

来解决它
passport.use(
    new FacebookTokenStrategy(
        {
            clientID: keys.facebookAppID,
            clientSecret: keys.facebookAppSecret,
            passReqToCallback: true
        },
        async (req, accessToken, refreshToken, profile, done) => {  
                 console.log(req.query.uniqueDeviceID);
        }
    )
);

因此无需将请求从路由器转发到策略回调。

authRouter.post(
    '/facebook/token',     
    passport.authenticate('facebook-token'),
      (req, res) => {
        res.send(req.user);
      }
  );