Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Oauth flow in Meteor

Within a Meteor app, can anyone guide me to how to allow users to simply Oauth Google?

There's the accounts-google package, but I don't want users to be able to login with it, just oauth and store credentials.

The docs mention "If you just want to authenticate to an Oauth service like Twitter, Facebook, or Google without using Accounts – that is, if you don't want to log the user in, you just want an OAuth token – you can use the underlying service packages such as twitter, facebook, and google directly.", but there are no docs whatsoever for the google package.

Any guidance would be much appreciated.

like image 936
99miles Avatar asked May 20 '15 03:05

99miles


1 Answers

The Oauth's package is intended to do just this. If you want to use it to get people's credentials

There are two options:

1) Modify the source of the google and accounts-google packages to remove the parts that log you in. There are no docs for this, i'm afraid, the best to understand it are the inline comments.

2) Use another atmosphere package to merge accounts-google with an existing login. So they're already logged in but can use Meteor.logInWithGoogle() to login with google and this is merged with their existing account. This way they don't have to log in with Google but you get to store the OAuth token. For this you can use the bozhao:link-accounts package, or the mikael:accounts-merge package:

// ON THE CLIENT:
Meteor.signInWithGoogle ({}, function (error, mergedUserId) {

  // mergedUsers is set if a merge occured
  if (mergedUserId) {
    console.log(mergedUserId, 'merged with', Meteor.userId());
  }
});

Then you would find the google OAuth token data in services.google on your existing Meteor.user() document.

like image 79
Tarang Avatar answered Sep 17 '22 07:09

Tarang