在node.js中对用户进行身份验证后检索Google网上论坛oauth护照申请:403未授权访问此资源/ api

问题描述

我在node.js应用程序中使用了Google护照,并且在成功通过身份验证后,尝试使用access_token检索当前用户所属的google组(我只想检查它们是否属于特定人群)。我已经在Google Developer Console中为客户端启用了Admin SDK。

passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_CLIENT_ID,clientSecret: process.env.GOOGLE_CLIENT_SECRET,callbackURL: `/auth/google/callback`
  },(accesstoken,refreshToken,profile,done) => {
    // find or create our local user here,if necessary
    // console.log(profile)

    const oauth2client = new google.auth.OAuth2();
    oauth2client.setCredentials({
        access_token: accesstoken
    }); 
    
    const directory = google.admin({ version: "directory_v1",auth: oauth2client });

    directory.groups
      .list({ domain: "mydomain.com" })
      .then(groups => {
        console.log(groups)
      })
      .catch(console.error);
    
    done(null,profile)
  }
))

我收到以下403错误

Not Authorized to access this resource/api

这是我的范围:

'https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/plus.profile.emails.read','https://www.googleapis.com/auth/admin.directory.group','https://www.googleapis.com/auth/admin.directory.group.member'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)