使用Passport JS的邀请系统

时间:2017-10-19 20:38:19

标签: node.js passport.js

我只使用Passport JS将身份验证系统重写为OAuth。我已经设计了如下所述的用户流程,但是我无法看到让Passport与原始请求中的信息进行交互的最佳位置。

流程将是:

  1. 经过身份验证的用户向新用户的电子邮件地址发送邀请
  2. 新用户点击链接并登陆邀请页面(/邀请/ SOMECODE)
  3. 已验证邀请代码,如果仍然有效,则允许用户通过Google / Slack
  4. 进行身份验证
  5. 新的个人资料在策略中创建,但与现有公司相关联(而非创建新公司)
  6. 我希望能够访问Google策略中的req.params,因为我通常会为首次使用的用户创建新的个人资料和公司。但如果有邀请码,我想在此时查看该信息。

    我无法看到支持此方法的任何文档,而Node Passport invitation strategy除了在初始注册后使用密码。

    您是否可以访问策略中的req对象,或者有更好的方法可以使用其他中间件来解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找的是passReqToCallback

docs中的示例:

passport.use(new TwitterStrategy({
    consumerKey: TWITTER_CONSUMER_KEY,
    consumerSecret: TWITTER_CONSUMER_SECRET,
    callbackURL: "http://www.example.com/auth/twitter/callback",
    passReqToCallback: true
  },
  function(req, token, tokenSecret, profile, done) {
    if (!req.user) {
      // Not logged-in. Authenticate based on Twitter account.
    } else {
      // Logged in. Associate Twitter account with user.  Preserve the login
      // state by supplying the existing user after association.
      // return done(null, req.user);
    }
  }
));

请参阅文档中的passReqToCallbackhttp://passportjs.org/docs/authorize