问题描述
我有一个简单的Meteor js应用程序,它允许您创建用户帐户并登录,或者通过oauth(由于accounts-google
软件包)使用现有的Google帐户登录.
I have a simple Meteor js app that allows you to create a user account and log in, or to log in with your existing Google account via oauth (thanks to the accounts-google
package).
使用该应用程序时,我输入我的用户名和密码,一切正常.但是,当我单击使用Google登录"时,google oauth弹出窗口要求我选择我要用于该登录的Google帐户.我选择了帐户,弹出窗口等待一秒钟,然后关闭,然后什么都没有发生.没有弹出窗口被阻止,没有登录失败"消息.好像什么都没有发生.
When using the app, I enter my username and password, everything works fine. However, when I click "Sign in with Google", the google oauth pop-up asks me to select which google account I want to use for this login. I select the account, the pop up waits a second, closes, and then nothing happens. No pop-ups being blocked, no "failed login" messages. It's as if nothing happened at all.
我确定使用oauth登录时永远不会定义用户,因为Meteor.user()
在JS控制台中为我提供了null
.
I'm certain that the user is never being defined when I use oauth login because Meteor.user()
gives me null
in the JS console.
这可能是怎么回事?或者我将如何调试呢?建议表示赞赏.
What could be going on here? Or how would I debug this? Suggestions appreciated.
p.s.如果需要任何其他信息,我可以提出补偿.
p.s. If any additional information is needed, I can ammend.
推荐答案
您可能在Meteor端或Google Developers Console端弄乱了oauth配置,因此这里有个简短的回顾.
You probably messed up oauth configuration either on the Meteor side or Google Developers Console side, so here is a quick recap.
Google开发者控制台:
Google Developers Console :
根据APIs& auth>凭据,请在OAuth部分中创建一个新的客户端ID.
Under APIs & auth > Credentials, create a new Client ID in the OAuth section.
选择Web应用程序并指定正确的重定向URI和JavaScript来源:
Choose Web Application and specify both correct redirect URIs and JavaScript origins :
重定向的URIS
http://localhost:3000/_oauth/google?close
http://your-production-domain.com/_oauth/google?close
JAVASCRIPT起源
JAVASCRIPT ORIGINS
http://localhost:3000
http://your-production-domain.com
流星配置:
请确保添加以下软件包:
Be sure to add these packages :
meteor add accounts-google
meteor add service-configuration
在server/config.js中,从 http://docs.meteor.com/#meteor_loginwithexternalservice添加这些行
In server/config.js, add these lines from http://docs.meteor.com/#meteor_loginwithexternalservice
ServiceConfiguration.configurations.remove({
service: "google"
});
ServiceConfiguration.configurations.insert({
service: "google",
clientId: "????????????????.apps.googleusercontent.com",
secret: "????????????????"
});
clientId和secret字段应设置为Google Developers Console中的字段.
The clientId and secret fields should be set to those in the Google Developers Console.
然后在您的登录表单的点击处理程序中调用Meteor.loginWithGoogle()
,它应该可以正常工作.
Then call Meteor.loginWithGoogle()
in the click handler of your login form and it should work as expected.
这篇关于(显然)成功登录后,Meteor.user为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!