将自定义查询参数添加到护照 auth0 策略身份验证请求

add custom query param to passport auth0 strategy authenticate request

我正在使用 passport.js 和 auth0 策略来授权用户

我也在使用 auth0 的托管登录页面,它支持像 customQueryParam here

这样的查询参数

例如:https://cool-startup.auth0.com/login?client=some_client_ID&...bunch of params...&customQueryParam=true

您可以使用 customQueryParam 来控制 auth0 托管的登录页面并显示即时消息和其他内容,非常方便

这是我的问题

在我的 auth0 中间件运行并且我确定我需要使用自定义参数将用户重定向回我的 auth0 登录页面后,我应该如何在使用 passport.js 的上下文中完成它/是吗可能的?

我在这里查看源代码 https://github.com/auth0/passport-auth0/blob/master/lib/index.js 继承自 https://github.com/jaredhanson/passport-oauth2/blob/9ddff909a992c3428781b7b2957ce1a97a924367/lib/strategy.js

我有点难过

这里是我发现错误的地方,我需要使用 url

中的自定义参数将用户重定向回 auth0
app.get('/auth/callback', (req, res, next) => {
  passport.authenticate('auth0', 
  {},
  (err, user) => {
    if (err) {
      // run passport.authenticate('auth0', 
      // again, but add custom query param 
    }
    return res.redirect('/');
  })(req, res, next);
});

非常感谢任何帮助/感谢阅读

您可以像此处那样自行构建 /authorize URL 并手动重定向:https://github.com/auth0-samples/auth0-regular-webapp-login-with-sso-and-api/blob/master/utils/authorize.js

由于 URL 在这里由您控制,您可以根据需要添加任何查询参数(尽管通常不鼓励将 non-standard 查询参数发送到登录页面)。