grails (11) vaadin (11) meteor (6) java (4) elasticsearch (3) apple (2) centos (1) cloudbees (1) google analytics (1) gradle (1) heroku (1) javafx (1) javascript (1) jdbc (1) jug (1) logback (1) logging (1) mac os (1) management (1) mongodb (1) mongolab (1) mysql (1) twitter (1) ubuntu (1)

Sunday, July 21, 2013

Meteor: How to login with Email, GitHub, Twitter, Google and Facebook account and add credentials to an existing user account

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.
TextLab for Mac
Ultimate application to validate, clean and format JSON, XML, SQL, HTML.