您需要使用公共域名或IP地址作为您的重定向URI,而不是本地计算机的“localhost”。
例如,您可以使用“localhost.com”代替“localhost”。
以下是示例代码,将重定向URI设置为“http://localhost.com:8000/auth/google/callback”:
passport.use(new GoogleStrategy({ clientID: GOOGLE_CLIENT_ID, clientSecret: GOOGLE_CLIENT_SECRET, callbackURL: "http://localhost.com:8000/auth/google/callback" }, function(accessToken, refreshToken, profile, done) { User.findOrCreate({ googleId: profile.id }, function (err, user) { return done(err, user); }); } ));
注意:您需要在hosts文件中'localhost.com”映射到您当前的IP地址。
在Windows上,您可以在以下目录中找到hosts文件:C:\Windows\System32\drivers\etc\hosts。
您可以使用文本编辑器(如Notepad)打开此文件并添加以下行:
127.0.0.1 localhost.com