Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeJS Passport-如何打开新窗口进行身份验证?_Javascript_Node.js_Passport.js - Fatal编程技术网

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

Javascript NodeJS Passport-如何打开新窗口进行身份验证?,javascript,node.js,passport.js,Javascript,Node.js,Passport.js,我正在使用Passport for NodeJS进行身份验证。我已经成功地集成了它。如果用户的cookie中已经有他的Github凭据,他只需单击我的登录按钮,就可以在我的仪表板上。但是,如果他没有cookies,我的应用程序会将他临时重定向到Github以输入他的凭据 我想添加一个功能,如果应用程序必须将用户重定向到Github,请在新窗口中这样做。这可能吗 在passport github示例中,调用了此函数,但显然,发生这种情况时我无法运行任何代码 // GET /auth/github

我正在使用Passport for NodeJS进行身份验证。我已经成功地集成了它。如果用户的cookie中已经有他的Github凭据,他只需单击我的登录按钮,就可以在我的仪表板上。但是,如果他没有cookies,我的应用程序会将他临时重定向到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')

因为这是在一个弹出的chrome扩展框中发生的,该扩展框不会转到github,因为github不会显示允许在一个小窗口中显示。所以除非我使用一个大窗口,否则它不会到达github。在何处尝试该代码段?这不是node.js服务器端解决方案,而是js/html解决方案。。请使用js/html中的相关代码更新您的问题