为OAat2Strategy对Passport / Node Express进行身份验证时,为什么会出现TokenError

时间:2014-07-08 14:02:07

标签: node.js express oauth oauth-2.0 passport.js

我尝试将Passuth JS的OAuth2Strategy与Express(4)结合使用。

在我重定向到登录后,它成功导航回我的回调网址,此时我收到以下错误:

TokenError: Invalid client or client credentials
    at OAuth2Strategy.parseErrorResponse (/www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12)
    at OAuth2Strategy._createOAuthError (/www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16)
    at /www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43
    at /www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18 at passBackControl (/www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9)
    at IncomingMessage.<anonymous> (/www/az-avatarz-server/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:919:16
    at process._tickDomainCallback (node.js:463:13)

我的护照配置如下:

passport.use("avatarz", new OAuth2Strategy({
        authorizationURL: authorizationURL,
        tokenURL: tokenURL,
        clientID: clientID,
        clientSecret: clientSecret,
        callbackURL: callbackURL
    },
    function (accessToken, refreshToken, profile, done) {
        User.find({
            prid: profile.prid
        }, function (error, user) {
            if (error) {
                return done(error);
            }

            if (user) {
                return done(null, user);
            }
            else {
                done(error);
            }
        });
    }
));

我的路线如下:

app.get('/authentication/provider', passport.authenticate("avatarz"));

app.get('/', passport.authenticate("avatarz", { failureRedirect: '/authentication/provider' }),
function (req, res) {
    res.sendfile("./public/index.html");
});

非常感谢任何帮助/建议!

1 个答案:

答案 0 :(得分:0)

确保您已通过以下网址激活Google+ API:https://console.developers.google.com