Request had insufficient authentication scopes after trying create Schema for google workspace directory with golang client

huangapple go评论133阅读模式
英文:

Request had insufficient authentication scopes after trying create Schema for google workspace directory with golang client

问题

我尝试使用Golang客户端为Google Workspace目录创建模式,使用的代码如下:

  1. config, err := google.ConfigFromJSON(b, admin.AdminDirectoryUserReadonlyScope, admin.AdminDirectoryUserScope,
  2. admin.AdminDirectoryCustomerScope, admin.AdminDirectoryCustomerReadonlyScope)
  3. if err != nil {
  4. log.Fatalf("无法解析客户端密钥文件为配置:%v", err)
  5. }
  6. srv, err := admin.NewService(ctx, option.WithHTTPClient(client))
  7. if err != nil {
  8. log.Fatalf("无法获取目录客户端:%v", err)
  9. }
  10. schemaCall := srv.Schemas.Insert("C03uwpzz5", &admin.Schema{
  11. Fields: []*admin.SchemaFieldSpec{
  12. {
  13. DisplayName: "显示名称",
  14. FieldName: "EmployeeNumber",
  15. FieldType: "STRING",
  16. MultiValued: false,
  17. },
  18. },
  19. })
  20. _, errDo := schemaCall.Do()
  21. if errDo != nil {
  22. log.Fatalf("无法获取目录客户端:%v", errDo)
  23. }

这段代码的参考资料如下:

  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

但是每次我都收到以下错误:

  1. 2023/02/16 00:38:11 无法获取目录客户端 googleapi: Error 403: 请求的身份验证范围不足。
  2. 详细信息:
  3. [
  4. {
  5. "@type": "type.googleapis.com/google.rpc.ErrorInfo",
  6. "domain": "googleapis.com",
  7. "metadata": {
  8. "method": "ccc.hosted.frontend.directory.v1.DirectorySchemas.Insert",
  9. "service": "admin.googleapis.com"
  10. },
  11. "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT"
  12. }
  13. ]
  14. 更多详细信息:
  15. 原因:insufficientPermissions,消息:权限不足

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

英文:

I tried to create Schema for the google workspace directory with golang client,
with this code:

  1. config, err := google.ConfigFromJSON(b, admin.AdminDirectoryUserReadonlyScope, admin.AdminDirectoryUserScope,
  2. admin.AdminDirectoryCustomerScope, admin.AdminDirectoryCustomerReadonlyScope)
  3. if err != nil {
  4. log.Fatalf("Unable to parse client secret file to config: %v", err)
  5. }
  6. srv, err := admin.NewService(ctx, option.WithHTTPClient(client))
  7. if err != nil {
  8. log.Fatalf("Unable to retrieve directory Client %v", err)
  9. }
  10. schemaCall := srv.Schemas.Insert("C03uwpzz5", &admin.Schema{
  11. Fields: []*admin.SchemaFieldSpec{
  12. {
  13. DisplayName: "Display Name",
  14. FieldName: "EmployeeNumber",
  15. FieldType: "STRING",
  16. MultiValued: false,
  17. },
  18. },
  19. })
  20. _, errDo := schemaCall.Do()
  21. if errDo != nil {
  22. log.Fatalf("Unable to retrieve directory Client %v", errDo)
  23. }

the reference of this code are these topics:

  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

but each time I'm receiving this error

  1. 2023/02/16 00:38:11 Unable to retrieve directory Client googleapi: Error 403: Request had insufficient authentication scopes.
  2. Details:
  3. [
  4. {
  5. "@type": "type.googleapis.com/google.rpc.ErrorInfo",
  6. "domain": "googleapis.com",
  7. "metadata": {
  8. "method": "ccc.hosted.frontend.directory.v1.DirectorySchemas.Insert",
  9. "service": "admin.googleapis.com"
  10. },
  11. "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT"
  12. }
  13. ]
  14. More details:
  15. 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

huangapple
  • 本文由 发表于 2023年2月16日 05:17:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定