Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google auth not writing to db #77

Open
rohitcolinrao opened this issue Feb 7, 2012 · 2 comments
Open

google auth not writing to db #77

rohitcolinrao opened this issue Feb 7, 2012 · 2 comments

Comments

@rohitcolinrao
Copy link

I'm having an odd issue where I'm able to authenticate and see my postback data and session using Google, but when I check MongoDB, there is no document for that login. I have tested this with Twitter and Facebook and am able to successfully write to mongo using them, it's weird it's only happening with Google.

@marni
Copy link

marni commented Mar 24, 2012

Have you found a resolution to this? I'm having a somewhat related issue with Google - in my case the Twitter goes and authenticates and writes to DB, and google authenticates with google, comes back, but hangs in an infinite loop and never writes anything to DB and never redirects back to '/'. If the timeout is not set to -1, it simply times out with:

modules/everymodule.js:348
  throw err;
        ^
Error: Step fetchOAuthUser of `google` module timed out.

Twitter and FB seem not to have any issues - just Google.

@EdHubbell
Copy link

Here's what I did (and I'm just starting out in Node, so I don't think I've got the chops to update code yet).

In example.js:
, scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'

Using both these scope addresses will get it working using id. You'll get a response like this:

{"id":"108165846879548747301","email":"[email protected]","verified_email":true,"name":"Ed Hubbell","given_name":"Ed","family_name":"Hubbell"}

In modules/google/plugin.js:

schema.static('createWithGoogleOAuth', function (googleUser, accessToken, accessTokenExtra, callback) {
var expiresDate = new Date;
expiresDate.setSeconds(expiresDate.getSeconds() + accessTokenExtra.expires_in);

var params = {
  google: {
      email: googleUser.email
    , id: googleUser.id
    , expires: expiresDate
    , accessToken: accessToken
    , refreshToken: accessTokenExtra.refresh_token
    , name: {
          full: googleUser.name
        , first: googleUser.given_name
        , last: googleUser.family_name
      }
  }
};

// TODO Only do this if password module is enabled
// Currently, this is not a valid way to check for enabled
if (everyauth.password)
  params[everyauth.password.loginKey()] = "google:" + googleUser.id; // Hack because of way mongodb treate unique indexes

and in modules/google/everyauth.js

User.findOne({'google.id': googleUser.id}, function (err, foundUser) {

and in schema.js:

module.exports = {
google:{
accessToken: String
, id: String
, expires: Date
, refreshToken: String
, email: String
, name: {
full: String
, first: String
, last: String
}
}
}

Hope this helps someone.
~Ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants