我们在 GCP 中托管了一个应用程序,它使用 GSuite API 将用户从 GSuite 同步到我们的应用程序,反之亦然。它曾经运行良好,直到最近我们的一些客户开始遇到问题。
我们开始得到
401 unauthorized. "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
我们的应用程序和授予的权限列表都没有变化。以下是授予的 api 访问权限列表:-
https://apps-apis.google.com/a/feeds/domain,
https://www.googleapis.com/auth/activity,
https://www.googleapis.com/auth/admin.directory.group,
https://www.googleapis.com/auth/admin.directory.orgunit,
https://www.googleapis.com/auth/admin.directory.user,**
https://www.googleapis.com/auth/admin.directory.user.readonly,
https://www.googleapis.com/auth/drive,
https://www.googleapis.com/auth/drive.appdata,
https://www.googleapis.com/auth/drive.file,
https://www.googleapis.com/auth/drive.metadata,
https://www.googleapis.com/auth/drive.metadata.readonly,
https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly,
https://www.googleapis.com/auth/admin.directory.rolemanagement,
https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly,
https://www.googleapis.com/auth/admin.directory.device.chromeos,
https://www.googleapis.com/auth/drive.apps.readonly,
https://www.googleapis.com/auth/drive.photos.readonly,
https://www.googleapis.com/auth/drive.scripts
受影响的 GSuite 域在昨天之前一直运行良好。还有一些域仍然可以正常工作。
有人可以建议问题出在哪里吗? API最近有什么变化吗?任何帮助将不胜感激。
最佳答案
"Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
有多种方法可以向 Google 进行身份验证。
- 基于网络的应用程序
- 原生应用
- 移动应用
- 和服务帐户
您为这些类型创建的客户端与使用它们的代码不同。您在上面看到的消息意味着您使用的代码与您创建的客户端类型不匹配。
确保您的代码专为与服务帐户一起使用而设计,并确保您从谷歌开发者控制台下载的凭据文件实际上是服务帐户的凭据。
为什么它以前工作并突然停止我不能告诉你这是一个错误,如果你的代码与你的凭据类型不匹配,你将永远遇到这个错误。
最后一个选项是仔细检查是否已在 Google 开发人员控制台中为您的服务帐户项目启用所有这些 API。
关于google-api - Google API 给出未经授权的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54667981/