尝试使用golang客户端为google workspace目录创建架构后,请求的身份验证范围不足

dtcbnfnu  于 2023-02-17  发布在  Go
关注(0)|答案(1)|浏览(123)

我试着用golang客户端为google workspace目录创建Schema,使用以下代码:

config, err := google.ConfigFromJSON(b, admin.AdminDirectoryUserReadonlyScope, admin.AdminDirectoryUserScope,
        admin.AdminDirectoryCustomerScope, admin.AdminDirectoryCustomerReadonlyScope)
    if err != nil {
        log.Fatalf("Unable to parse client secret file to config: %v", err)
    }
    srv, err := admin.NewService(ctx, option.WithHTTPClient(client))
    if err != nil {
        log.Fatalf("Unable to retrieve directory Client %v", err)
    }

    schemaCall := srv.Schemas.Insert("C03uwpzz5", &admin.Schema{
        Fields: []*admin.SchemaFieldSpec{
            {
                DisplayName: "Display Name",
                FieldName:   "EmployeeNumber",
                FieldType:   "STRING",
                MultiValued: false,
            },
        },
    })
    _, errDo := schemaCall.Do()
    if errDo != nil {
        log.Fatalf("Unable to retrieve directory Client %v", errDo)
    }

此代码参考包括以下主题:

  1. https://developers.google.com/admin-sdk/directory/v1/guides/manage-schemas#create_schema
  2. https://developers.google.com/admin-sdk/directory/v1/quickstart/go
    但每次我收到这个错误
2023/02/16 00:38:11 Unable to retrieve directory Client googleapi: Error 403: Request had insufficient authentication scopes.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.ErrorInfo",
    "domain": "googleapis.com",
    "metadata": {
      "method": "ccc.hosted.frontend.directory.v1.DirectorySchemas.Insert",
      "service": "admin.googleapis.com"
    },
    "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT"
  }
]

More details:
Reason: insufficientPermissions, Message: Insufficient Permission

我尝试了所有相关的范围,不幸的是,我找不到正确的。

rjzwgtxy

rjzwgtxy1#

我找到了正确的瞄准镜。是https://www.googleapis.com/auth/admin.directory.userschema

相关问题