【问题标题】:add custom query param to passport auth0 strategy authenticate request将自定义查询参数添加到护照 auth0 策略身份验证请求
【发布时间】:2018-08-01 17:40:08
【问题描述】:

我正在使用 passport.js 和 auth0 策略来验证用户

我也在使用auth0的托管登录页面,这里支持customQueryParam等查询参数

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

您可以使用customQueryParam 来控制auth0 托管的登录页面并显示flash 消息和东西,很方便

这是我的问题

在我的 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);
});

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

【问题讨论】:

    标签: node.js passport.js auth0


    【解决方案1】:

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

    由于此处的 URL 由您控制,因此您可以根据需要添加任何查询参数(尽管通常不鼓励将非标准查询参数发送到登录页面)。

    【讨论】:

    • 谢谢,这几乎就是我最终要做的事情,我明白它为什么不受欢迎,但它会让我们克服困难,直到我们转向纯粹的象征性方法。
    猜你喜欢
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 2016-12-26
    相关资源
    最近更新 更多