When an user has already an account in the Meteor application, we don't want to create another user in MongoDB when he tries to login with other OAuth service. Rather we connect the accounts and add a new login service to the existing user's services collection.
This code doesn't work for Twitter, because Twitter does not return email in the user data. Therefore, there is no way how to to connect Twitter account by email. I propose to exclude Twitter from your application until it is solved by Meteor (requestPermissions).
Also Github can have an account without email. So when user tries to login with GitHub without email, a new account is created.
Just create a new file oauth.js in server folder and copy paste the code below.
Thanks to Gadi Cohen post.
kinda think performing 4 queries (or one per service) could be optimized a bit..
ReplyDeleteIf the user doesn't have an email associated with the service, or the email associated with the service does not match on their external service then this breaks?
ReplyDeleteService Google does not have appId. It must be renamed to clientId.
ReplyDeleteThere is small problem in your code. It won't work. You expect "user" in Accounts.onCreateuser to have loginTokens as well, however, loginTokens are generated after user object is returned from this function back to Meteor. Hence, following line will cause error
ReplyDeleteexistingUser.services.resume.loginTokens.push(
user.services.resume.loginTokens[0]
);
You should comment these lines and it will work smoothly.