【问题标题】:Making calls to Google service account without using domain admin user在不使用域管理员用户的情况下调用 Google 服务帐户
【发布时间】:2015-04-08 16:09:56
【问题描述】:

我正在尝试使用 Directory API 为我们域中的用户更新 Google 密码。我遵循了 Plus 服务帐户的示例,它几乎相同 (https://github.com/google/google-api-java-client-samples/blob/master/plus-serviceaccount-cmdline-sample/src/main/java/com/google/api/services/samples/plus/serviceaccount/cmdline/PlusServiceAccountSample.java)。

我正在尝试确定为什么需要将超级管理员用户的电子邮件地址传递给 setServiceAccountUser() 以便在域上设置用户密码。是否有某个设置可以让我在不设置 serviceAccountUser 的情况下使用 API?

当我注释掉 setServiceAccountUser() 调用时,我收到以下消息:

{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Not Authorized to access this resource/api",
"reason" : "forbidden"
} ],
"message" : "Not Authorized to access this resource/api"

以下是相关的代码(来自 Plus 示例):

// service account credential (uncomment setServiceAccountUser for domain-wide delegation)
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
        .setJsonFactory(JSON_FACTORY)
        .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
        .setServiceAccountScopes(Collections.singleton(PlusScopes.PLUS_ME))
        .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
        // .setServiceAccountUser("user@example.com")
        .build();

【问题讨论】:

    标签: java google-api google-directory-api


    【解决方案1】:

    目录 API 写入操作需要管理员帐户。超级管理员或有权执行 API 用户修改的delegated admin。这在prerequisites 文档中列出。

    【讨论】:

    • 谢谢...我不太明白为什么会这样,因为您不必传递管理员用户的凭据以及调用意味着您基本上可以传递任何管理员用户的只需知道电子邮件地址即可将电子邮件地址发送到此属性。也许谷歌添加了这个作为防止意外写入调用的要求?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 2017-04-29
    • 2015-05-10
    • 1970-01-01
    相关资源
    最近更新 更多