3

我正在使用 nodejs npm 模块passport-google-oauth2

我目前完全按照其示例显示的方式使用它,并在成功验证后使用 google oauth 将回调的重定向 URI:

例子:

服务器端:

var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy;

passport.use(new GoogleStrategy({
    clientID:     GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: "http://yourdormain:3000/auth/google/callback",
    passReqToCallback   : true
  },
  function(request, accessToken, refreshToken, profile, done) {
    User.findOrCreate({ googleId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

客户端:

app.get('/auth/google',
  passport.authenticate('google', { scope: 
    [ 'https://www.googleapis.com/auth/plus.login',
      'https://www.googleapis.com/auth/plus.profile.emails.read' ] }
));

app.get( '/auth/google/callback', 
    passport.authenticate( 'google', { 
        successRedirect: '/auth/google/success',
        failureRedirect: '/auth/google/failure'
}));

我知道有一种无需重定向即可使用 Google OAuth 的方法;它只是以某种方式停留在同一页面上(Google SSO)。我认为您可以只使用 a 来完成GoogleVerifier,而不是构建 a new GoogleAuthorizationCodeTokenRequest()(Java示例),但在这一点上我很迷茫。

问题:

  1. 如何在没有重定向 URI 的情况下使用 google oauth2?(我知道可以使用 Java 中的 GoogleVerifier 对象来完成)。

  2. 我在 NodeJS 中为 Google SSO 使用了错误的模块吗?上面的模块是否适合使用 OAuth2 的 Google SSO?它适用于 Google OAuth2,但它支持 SSO 吗?

提前感谢您的帮助

4

0 回答 0