google-api - 为 google plus 交换 oauth2 token 时出现 "policy_enforced"错误

标签 google-api google-oauth google-api-dotnet-client

在上周二之前,我们的应用程序一直运行良好。在为 google plus 交换 oauth2 token 时,我们不断收到“policy_enforced”错误。谷歌的回应是:

Google.Apis.Auth.OAuth2.Responses.TokenResponseException: 
Error:"policy_enforced", 
Description:"Access denied by a security policy established by the Google Apps administrator of your organization. Please contact your administrator for further assistance.", 
Uri:""

我们使用的是 google-api-dotnet-client,代码非常简单。

var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
    DataStore = new CustomGoogleDataStore(),
    ClientSecrets = new global::Google.Apis.Auth.OAuth2.ClientSecrets { ClientId = client.ID, ClientSecret = client.Secret },
    Scopes = scopes.Split(' '),
});
var token = flow.ExchangeCodeForTokenAsync(guid, code, redirectUri, CancellationToken.None).Result;

范围是:

"https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/plus.profile.emails.read",
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email",
"https://mail.google.com/"

这个问题是随机发生的。直到现在我都找不到 100% 重现它的方法。

请让我知道这是什么问题,如有任何建议,我们将不胜感激。

最佳答案

我最近遇到了同样的问题。联系 Google 团队后,我们发现此问题是由于授权范围与我们在登录时请求的范围不匹配而导致的。我们使用了最新的授权范围 profileemail用户登录时。但在 GAM API 控制台中,Google 对已弃用的范围进行了硬编码
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email

将最新的授权范围恢复为弃用的范围后,登录工作正常。

关于google-api - 为 google plus 交换 oauth2 token 时出现 "policy_enforced"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25508740/

相关文章:

php - OAuth 是否允许 localhost 进行调试?

google-api - 谷歌日历 API : Calendar usage limits exceeded

c# - 无法以正确的格式对特殊字符电子邮件进行编码,gmail api & ae.net.mail

c# - 在 C# 中使用 OAuth2 通过 Google API 进行身份验证

c# - Gmail API - 值 '= Get Labels google-api-dotnet-client/1.25.0.0 (gzip)' 的格式无效

javascript - 如何使用 Google Maps API 在标记上设置弹出窗口?

google-api - 是否可以以编程方式创建 google API KEY?

javascript - Google 登录 API 挂起并出现 Uncaught Error 无法从 URL 哈希获取父源

ruby - Google oauth 如何交换访问 token 和 ID token 的代码

python - 错误 : "unrecognized arguments: shell" - OAuth 2. 0 Python 的 Google API 客户端