Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 护照+;节点中的Google令牌+;Express应用程序不断抛出';未经授权';对于邮递员的尝试,令牌是良好的,并且经过手动验证_Node.js_Passport.js_Google Oauth_Passport Google Oauth2 - Fatal编程技术网

Node.js 护照+;节点中的Google令牌+;Express应用程序不断抛出';未经授权';对于邮递员的尝试,令牌是良好的,并且经过手动验证

Node.js 护照+;节点中的Google令牌+;Express应用程序不断抛出';未经授权';对于邮递员的尝试,令牌是良好的,并且经过手动验证,node.js,passport.js,google-oauth,passport-google-oauth2,Node.js,Passport.js,Google Oauth,Passport Google Oauth2,我有一个用Node+Express+Passport构建的后端restapi,我正在尝试使用googleaccess令牌进行身份验证。我正在使用 我已经在github上查看了包的文档和问题,但没有解决任何问题 我已根据以下内容验证访问令牌: https://www.googleapis.com/oauth2/v1/tokeninfo?idToken带有id标记和https://www.googleapis.com/oauth2/v1/tokeninfo?acessToken使用访问令牌,两者都有

我有一个用Node+Express+Passport构建的后端restapi,我正在尝试使用googleaccess令牌进行身份验证。我正在使用

我已经在github上查看了包的文档和问题,但没有解决任何问题

我已根据以下内容验证访问令牌:

https://www.googleapis.com/oauth2/v1/tokeninfo?idToken
带有id标记和
https://www.googleapis.com/oauth2/v1/tokeninfo?acessToken
使用访问令牌,两者都有效,但都不起作用。我在后端和前端双重检查了我是否使用了正确的clientID和secret,并从中获得了令牌

以下是相关代码:

    app.use(passport.initialize());
    passport.use(
      new GoogleTokenStrategy(
        {
          clientID: config.get('google.clientID'),
          clientSecret: config.get('google.clientSecret')
        },
        function(accessToken, refreshToken, profile, done) {

console.log(accessToken, refreshToken, profile, done)

          User.findOrCreate({ googleId: profile.id }, function(err, user) {
            return done(err, user);
          });
        }
      )
    );
    
    app.use('/user', passport.authenticate('google-token'), userRoute);
我在顶部导入如下内容:

const passport = require('passport');
const GoogleTokenStrategy = require('passport-google-token').Strategy;
该应用程序没有抛出任何类型的错误


我在创建策略的地方添加了console.log——当我从postman启动时,没有任何日志记录。当我从有角度的前端发射时——它记录数据并发射。

在我的例子中,这是因为User.findOrCreate逻辑被抛出的,我甚至没有定义它。Facebook token passport软件包因此引发了一个内部服务器错误,但google软件包只会在没有消息的情况下悄无声息地失败

我将在以后的开发过程中定义findOrCreate逻辑。目前,这适用于测试:

  new GoogleTokenStrategy(
    {
      clientID: config.get('google.clientID'),
      clientSecret: config.get('google.clientSecret')
    },
    function(accessToken, refreshToken, profile, done) {
      return done(null, profile);
    }
  )
);