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

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

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)
}

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

  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 无法获取目录客户端 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:

  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

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

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:

确定