NodeJS Passport - 如何打开一个新窗口进行身份验证

NodeJS Passport - how to open a new window for authentication?

本文关键字:新窗口 窗口 身份验证 一个 Passport 何打开 NodeJS      更新时间:2023-09-26

我正在使用Passport for NodeJS进行身份验证。我已经成功地集成了它。如果用户的 cookie 中已经有他的 Github 凭据,他只需单击我的登录按钮,他就会在我的仪表板上。 但是,如果他没有 cookie,我的应用程序会暂时将他重定向到 Github 以输入他的凭据。

我想添加的功能,如果应用程序必须将用户重定向到 Github,请在新窗口中执行此操作。这可能吗?

在 passport-github 示例中调用了此函数,但显然发生这种情况时我无法运行任何代码?

// GET /auth/github
//   Use passport.authenticate() as route m function(req,res)iddleware to authenticate the
//   request.  The first step in GitHub authentication will involve redirecting
//   the user to github.com.  After authorization, GitHubwill redirect the user
//   back to this application at /auth/github/callback
app.get('/auth/github',
  passport.authenticate('github'),
  function(req, res){
    // The request will be redirected to GitHub for authentication, so this
    // function will not be called.
  });

为什么要让用户在不同的窗口中重定向?GitHub 身份验证不会通过重定向将用户发送回您的应用程序吗?

也许尝试:

window.open('/auth/github')