【问题标题】:Google Group Settings API enabled for service accounts?为服务帐户启用了 Google Group Settings API?
【发布时间】:2012-12-08 09:20:50
【问题描述】:

大多数 Google Management API 似乎都已为服务帐户启用。例如,我可以像这样检索日历:

string scope = Google.Apis.Calendar.v3.CalendarService.Scopes.Calendar.ToString().ToLower();
string scope_url = "https://www.googleapis.com/auth/" + scope;
string client_id = "999...@developer.gserviceaccount.com";
string key_file = @"\path\to\my-privatekey.p12";
string key_pass = "notasecret";

AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
X509Certificate2 key = new X509Certificate2(key_file, key_pass, X509KeyStorageFlags.Exportable);

AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = client_id, Scope = scope_url };
OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

CalendarService service = new CalendarService(auth);
var x = service.Calendars.Get("calendarID@mydomain.com").Fetch();

但是,GroupssettingsService 上的相同代码返回 503 - 服务器不可用。这是否意味着服务帐户不能与该 API 一起使用?

在一个可能相关的问题中,Groups Settings Service 的范围似乎是 apps.groups.settings 但如果您致电

GroupssettingsService.Scopes.AppsGroupsSettings.ToString().ToLower();

...你得到的是appsgroupssettings,没有嵌入的句点。

是否有其他方法可以为 GroupssettingsService 使用服务帐户?或者关于正确范围字符串的任何信息?

非常感谢。

【问题讨论】:

    标签: google-groups-api google-admin-settings-api google-groups-settings


    【解决方案1】:

    一段时间后,我找到了这个线程,以及文档中最重要的部分。发帖以免其他人在未来浪费时间。

    Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

    See the "About authorization protocols" section of the docs

    【讨论】:

      【解决方案2】:

      为什么需要为此使用服务帐号?您可以使用常规 OAuth 2.0 授权流程从 Google Apps 超级管理员用户获取授权令牌并使用它:

      https://developers.google.com/accounts/docs/OAuth2InstalledApp

      【讨论】:

      • 好吧,出于同样的原因,您需要一个服务帐户——允许受信任的后端应用程序使用提升到用户级别的存储凭据进行更新。在这种情况下,一些非超级用户可以定义电子邮件组;该应用程序使用 GData Groups API 创建和填充组。理想情况下,它会使用 Groupssettings API 来进行我不希望用户能够关闭的某些策略设置(例如审核)。
      • 您可以简单地创建一个真正的 Google Apps 用户,以便单独用作服务帐户。这当然意味着每年 50 美元,但考虑到这应该不算坏。用户需要是超级管理员,但 OAuth2 令牌的范围仅限于 Groups Settings API,因此访问权限很小。
      • 对我们免费(教育),但这仍然需要三足授权。除非我弄错了(我很乐意这样做),否则“服务帐户”是新的 Google Apps API 适应 2-legged 授权的方式。所以我写了 2LO 访问代码,但是这个特殊的 API(Groupssettings)似乎过滤掉了这些请求。
      • 是的,这将是 3-legged OAuth,但您只需为服务帐户(由您控制​​)执行一次身份验证。然后你的访问令牌是好的,直到手动撤销。 3-legged OAuth 是 GAM 验证和使用 Group Settings API 的方式(尽管它使用 OAuth 1.0,正在升级到 2.0)code.google.com/p/google-apps-manager/wiki/…
      • 嗯。我没有意识到这是一个有效的流程。我原以为令牌会像往常一样过期。好吧,我会去的。谢谢。
      猜你喜欢
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      相关资源
      最近更新 更多