trailsjs / sails-auth

Passport-based User Authentication system for sails.js applications. Designed to work well with the sails-permissions module.
https://www.npmjs.org/package/sails-auth
MIT License
265 stars 141 forks source link

Google Sign in Issues #72

Closed drouillard closed 8 years ago

drouillard commented 8 years ago

New to Sails, spent many hours trying to get Google Sign-in via Passport. Here are issues I have encountered

  1. It seems like I have to overwrite the google credentials in /node_modules/sails-auth/config/passport.js rather than my own config/passport.js. I am sure this is incorrect, but could not get it work by copying / pasting what was in the node module passport.js into my own. How do I make this work with my own config/passport.js? Currently trying

    // config/passport.js
    
        var _ = require('lodash');
     var _super = require('sails-permissions/config/passport');
        _.merge(exports, _super);
        _.merge(exports, {
        // Extend with custom logic here by adding additional fields, methods, etc.
    
    google: {
          name: 'Google',
           protocol: 'oauth2',
              strategy: require('passport-google-oauth').OAuth2Strategy,
            options: {
               clientID: 'my_id',
                clientSecret: 'my_secret',
               scope: ['profile', 'email']
            }
           }
      });
  2. Using default permissions after following instructions on sails-permissions, I can't properly create a user. The is stuck behind permissions it seems, and there is no clear way to enable it. I can get to /auth/google but not to /auth/google/callback. How do I easily disable permissions for now?
  3. I had to manually install the passport-google-oauth package. But yet it seems like it should be it is already included as a dependency. I am using NVM. Encountered this with lodash as well. Does this seem right?

    npm install passport-google-oauth --save
  4. It is not clear how I would use Sails Js with Googles iOS native cocoa pod that handles sign-ins. Can I pass in an access_token/refresh_token here instead of using the web redirect? If not, do I need another passport strategy?
  5. I was able to create a user via web sign-in, but I don't see where the Google specific info is stored in my database. I see the user in the users table, but I don't see the refresh token stored anywhere. My passport table is empty. Where is this info stored?
  6. When I authenticate with same email address many times I get a warning about a user already existing. Similar to #64 Do I need to do something special to handle this situation?
slavafomin commented 8 years ago

Your passport.js should look like this:

_.merge(exports, {
  passport: {
    google: {
      options: {
        clientID: '...',
        clientSecret: '...'
      }
    }
  }
});
drouillard commented 8 years ago

Thanks. I will give that a shot

drouillard commented 8 years ago

Ended up not using Sails Auth at all.

https://developers.google.com/identity/sign-in/ios/backend-auth

https://github.com/google/google-api-nodejs-client/

Get the access_token from the Google iOS native sign-in process and then pass to back-end. Once you get the token then can verify with Google

var google = require('googleapis');
var plus = google.plus('v1');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);

// Retrieve tokens via token exchange explained above or set them:
oauth2Client.setCredentials({
  access_token: 'ACCESS TOKEN HERE',
  refresh_token: 'REFRESH TOKEN HERE'
});

plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, response) {
  // handle err and response
});