英文:
Request had insufficient authentication scopes after trying create Schema for google workspace directory with golang client
问题
我尝试使用Golang客户端为Google Workspace目录创建模式,使用的代码如下:
config, err := google.ConfigFromJSON(b, admin.AdminDirectoryUserReadonlyScope, admin.AdminDirectoryUserScope,
admin.AdminDirectoryCustomerScope, admin.AdminDirectoryCustomerReadonlyScope)
if err != nil {
log.Fatalf("无法解析客户端密钥文件为配置:%v", err)
}
srv, err := admin.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
log.Fatalf("无法获取目录客户端:%v", err)
}
schemaCall := srv.Schemas.Insert("C03uwpzz5", &admin.Schema{
Fields: []*admin.SchemaFieldSpec{
{
DisplayName: "显示名称",
FieldName: "EmployeeNumber",
FieldType: "STRING",
MultiValued: false,
},
},
})
_, errDo := schemaCall.Do()
if errDo != nil {
log.Fatalf("无法获取目录客户端:%v", errDo)
}
这段代码的参考资料如下:
-
https://developers.google.com/admin-sdk/directory/v1/guides/manage-schemas#create_schema
-
https://developers.google.com/admin-sdk/directory/v1/quickstart/go
但是每次我都收到以下错误:
2023/02/16 00:38:11 无法获取目录客户端 googleapi: Error 403: 请求的身份验证范围不足。
详细信息:
[
{
"@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"
}
]
更多详细信息:
原因:insufficientPermissions,消息:权限不足
我尝试了所有相关的范围,但不幸的是找不到正确的范围。
英文:
I tried to create Schema for the google workspace directory with golang client,
with this code:
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)
}
the reference of this code are these topics:
-
https://developers.google.com/admin-sdk/directory/v1/guides/manage-schemas#create_schema
-
https://developers.google.com/admin-sdk/directory/v1/quickstart/go
but each time I'm receiving this error
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
I tried all related scopes and unfortunately I could not fin the right one.
答案1
得分: 1
我找到了正确的范围。
它是 https://www.googleapis.com/auth/admin.directory.userschema
。
英文:
I found the correct scope.
It's https://www.googleapis.com/auth/admin.directory.userschema
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论