Google oauth & apis how to do it

前端 未结 1 748
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 08:43

I can\'t find any documentation on using google oauth and google apis which I understand. At the moment, I am doing this, but it is not a complete guide: https://developers.goog

相关标签:
1条回答
  • 2021-01-27 09:21

    Have you had a look at PassportJS? It has a very solid implementation for Google

    I have done something similar for Facebook and will paste it here in case it helps:

    So firstly, I added the below into my node app:

    var passport = require('passport');
    var FacebookStrategy = require('passport-facebook').Strategy;
    

    Then, the below:

    app.use(passport.initialize());
    app.use(passport.session());
    

    Then, the below:

    passport.serializeUser(function(user, done){
        done(null, user.id);
    });
    
    passport.deserializeUser(function(id, done){
        userModel.findById(id, function(err, user){
            done(err, user);
        });
    });
    
    passport.use(new FacebookStrategy({
    clientID: config.facebook.appID,
    clientSecret: config.facebook.appSecret,
    callbackURL: config.facebook.callbackURL,
    profileFields: ['id', 'displayName', 'photos', 'emails', 'birthday', 'location', 'bio', 'likes.limit(100)']
    },
    function(accessToken, refreshToken, profile, done){
        //Do whatever I want
    }
    )
    );
    

    I won't explain all this but - see if it helps you with your Google apps integration. Good luck!

    0 讨论(0)
提交回复
热议问题