护照和不同的callbackURI?

时间:2019-05-22 21:34:55

标签: node.js passport.js passport-google-oauth

我的基于NodeJS的应用程序通过password-google-oauth20支持Google OAuth2,并且还基于访问它的URL提供了多个前端。有什么办法可以让我拥有不同的redirectURL?

这是初始代码:

passport.use(new GoogleStrategy({
        clientID: 'clientid.apps.googleusercontent.com',
        clientSecret: 'somesecret',
        callbackURL: 'http://localhost:8000/auth/google/callback',
    },
    (accessToken, refreshToken, profile, done) => {
        done(null, profile); // passes the profile data to serializeUser
    }
));

然后是Google身份验证的端点:

app.get('/auth/google', passport.authenticate('google', {
    scope: 'openid profile email',
    responseType: 'code',
}));

这对于单个站点来说很好,但是由于我需要能够支持多个前端,所以我正在尝试:

app.get('/auth/google', passport.authenticate('google', {
    scope: 'openid profile email',
    responseType: 'code',
    successRedirect: 'http://localhost:8000/auth/google/callback2'
}));

不幸的是,这不起作用。我确实尝试从GoogleStrategy构造函数中删除“ callbackURL”,但这最终导致在调用passport.authenticate()时,格式为“缺少所需的参数:redirect_uri”。

这是我正在尝试做的事情,如果可以的话,怎么做?如果没有,可以采用其他方法。

0 个答案:

没有答案