简体   繁体   English

InternalOAuthError:无法在nodejs中获取请求令牌passport-google

[英]InternalOAuthError: Failed to obtain request token passport-google in nodejs

I am trying to authenticate user, using google authentication passport-google but it keeps sending InternalOAuthError: Failed to obtain request token . 我正在尝试使用google身份验证passport-google对用户进行身份验证,但它一直在发送InternalOAuthError:无法获取请求令牌

error view 错误视图

InternalOAuthError: Failed to obtain request token at Strategy.OAuthStrategy._createOAuthError (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/passport-oauth1/lib/strategy.js:396:17) at /Users/menaka/WebstormProjects/cardCreaterServer/node_modules/passport-oauth1/lib/strategy.js:244:41 at /Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:543:17 at passBackControl (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:397:13) at IncomingMessage. InternalOAuthError:无法在/ Users / menaka / WebstormProjects / cardCreaterServer / node_modules上的Strategy.OAuthStrategy._createOAuthError(/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/passport-oauth1/lib/strategy.js:396:17)获取请求令牌/passport-oauth1/lib/strategy.js:244:41 atUsers/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:543:17 at passBackControl(/ Users / menaka / WebstormProjects / cardCreaterServer / node_modules /oauth/lib/oauth.js:397:13)在IncomingMessage。 (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:409:9) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:921:12) (/Users/menaka/WebstormProjects/cardCreaterServer/node_modules/oauth/lib/oauth.js:409:9)在emitNadableNT的IncomingMessage.emit(events.js:166:7)的emitNone(events.js:72:20)处(_stream_readable.js:921:12)
at nextTickCallbackWith2Args (node.js:442:9) at process._tickCallback (node.js:356:17) 在process._tickCallback(node.js:356:17)的nextTickCallbackWith2Args(node.js:442:9)

I have already enabled Google + api inside the google API Manager platform.and here is my Authorized JavaScript origins 我已经在google API Manager平台中启用了Google + api。这里是我的授权JavaScript来源

http://localhost:3000 HTTP://本地主机:3000

and Authorized redirect URIs 授权的重定向URI

http://localhost:3000/auth/google/callback HTTP://本地主机:3000 /认证/谷歌/回调

in side my routes.js file 在我的routes.js文件中

var User = require('./models/user');
module.exports = function(app, passport){
    app.get('/', function(req, res){
        res.render('index.ejs');
    });

    app.get('/login', function(req, res){
        res.render('login.ejs', { message: req.flash('loginMessage') });
    });
    app.post('/login', passport.authenticate('local-login', {
        successRedirect: '/profile',
        failureRedirect: '/login',
        failureFlash: true
    }));

    app.get('/signup', function(req, res){
        res.render('signup.ejs', { message: req.flash('signupMessage') });
    });


    app.post('/signup', passport.authenticate('local-signup', {
        successRedirect: '/',
        failureRedirect: '/signup',
        failureFlash: true
    }));

    app.get('/profile', isLoggedIn, function(req, res){
        res.render('profile.ejs', { user: req.user });
    });

    app.get('/auth/google', passport.authenticate('google', {scope: ['profile','email']}));

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


    app.get('/logout', function(req, res){
        req.logout();
        res.redirect('/');
    })
};

function isLoggedIn(req, res, next) {
    if(req.isAuthenticated()){
        return next();
    }

    res.redirect('/login');
}

inside my passport.js 在我的passport.js里面

var LocalStrategy = require('passport-local').Strategy;

var GoogleStrategy = require('passport-google-oauth').OAuthStrategy;

var User            = require('../app/models/user');

var configAuth=require('./auth');

module.exports = function(passport) {


    passport.serializeUser(function(user, done){
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done){
        User.findById(id, function(err, user){
            done(err, user);
        });
    });


    passport.use('local-signup', new LocalStrategy({
            usernameField: 'email',
            passwordField: 'password',
            passReqToCallback: true
        },
        function(req, email, password, done){
            process.nextTick(function(){
                User.findOne({'local.username': email}, function(err, user){
                    if(err)
                        return done(err);
                    if(user){
                        return done(null, false, req.flash('signupMessage', 'That email already taken'));
                    } else {
                        var newUser = new User();
                        newUser.local.username = email;
                        newUser.local.password = newUser.generateHash(password);

                        newUser.save(function(err){
                            if(err)
                                throw err;
                            return done(null, newUser);
                        })
                    }
                })

            });
        }));

    passport.use('local-login', new LocalStrategy({
            usernameField: 'email',
            passwordField: 'password',
            passReqToCallback: true
        },
        function(req, email, password, done){
            process.nextTick(function(){
                User.findOne({ 'local.username': email}, function(err, user){
                    if(err)
                        return done(err);
                    if(!user)
                        return done(null, false, req.flash('loginMessage', 'No User found'));
                    if(!user.validPassword(password)){
                        return done(null, false, req.flash('loginMessage', 'invalid password'));
                    }
                    return done(null, user);

                });
            });
        }
    ));

    passport.use(new GoogleStrategy({
            consumerKey: configAuth.GoogleAuth.clientID,
            consumerSecret: configAuth.GoogleAuth.clientSecret,
            callbackURL: configAuth.GoogleAuth.callbackURL
        },
        function(accessToken, refreshToken, profile, done) {
            process.nextTick(function(){
                User.findOne({'google.id':profile.id},function(err,user){
                    if(err){
                        return done(err);
                    }
                    if(user){
                        return done(null,user);
                    }else{
                        var newUser=new User();
                        newUser.google.id=profile.id;
                        newUser.google.token=accessToken;
                        newUser.google.name=profile.displayName;
                        newUser.google.email=profile.emails[0].value;

                        newUser.save(function(err){
                            if(err){
                                throw err;
                            }
                            return done(null,newUser);
                        })
                    }
                });
            });
        }
    ));




};

the callbackURL is callbackURL是

http://localhost:3000/auth/google/callback HTTP://本地主机:3000 /认证/谷歌/回调

what do i have to do in order to fix this issue ? 为了解决这个问题,我该怎么办?

尝试转到/node_modules/passport-oauth1/lib/strategy.js:396:17) ,然后在console.log输入错误消息,并查看输出。

Banged my head on this for awhile - seems like there's an old link reference in the basic strategy. 我暂时搁置了这个问题 - 似乎在基本策略中有一个旧的链接参考。 Recommend you try 推荐你试试

https://github.com/jaredhanson/passport-google-oauth2 https://github.com/jaredhanson/passport-google-oauth2

instead. 代替。 It's up-to-date and worked immediately for me! 它是最新的,并立即为我工作!

*The debug solution got me to this solve, btw. *调试解决方案让我解决了这个问题,顺便说一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InternalOAuthError:无法获取访问令牌Twitch - InternalOAuthError: Failed to obtain access token Twitch Passport-facebook-token返回InternalOAuthError:验证令牌时无法获取用户个人资料 - passport-facebook-token returns InternalOAuthError: Failed to fetch user profile when verifying the token 使用passport-google-oauth20 InternalOAuthError获取错误:无法获取用户配置文件并且在将标头发送到客户端后无法设置标头 - Getting erros using passport-google-oauth20 InternalOAuthError: Failed to fetch user profile and Cannot set headers after they are sent to the client Strongloop Passport.js身份验证-“无法获取访问令牌” - Strongloop Passport.js authentication - “Failed to obtain access token” 如何使用node.js模块Passport-google - How do I use the node.js module passport-google Passport-twitter:在会话中找不到请求令牌 - Passport-twitter: failed to find request token in session Nodejs中的护照OAuth2Strategy是否对访问令牌发出自动POST请求 - Does passport OAuth2Strategy in Nodejs make automatic POST request for access token NodeJS + Passport,检索访问令牌(Spotify API) - NodeJS + Passport, retrieving an access token (Spotify API) 500的NodeJ在处理时无法获取访问令牌(错误:连接ECONNREFUSED)._ tickCallback(node.js:419:13) - NodeJs, 500 failed to obtain access token (Error: connect ECONNREFUSED) at at process._tickCallback (node.js:419:13) Nodejs Passport - 使用多个Google策略 - Nodejs Passport - Using Multiple Google Strategies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM