我想对 Gsuite 用户进行身份验证,以便他们能够从我公司的应用程序中创建组,我必须使用 CURL 进行此操作,我应该向哪个 URL 发送发布请求?
例如,如果我想让用户登录 Google plus,我会点击这个 url
CURLOPT_URL => "https://www.googleapis.com/plus/v1/people/me?access_token=" . $access_token,
Gsuite 的网址是什么?
我想对 Gsuite 用户进行身份验证,以便他们能够从我公司的应用程序中创建组,我必须使用 CURL 进行此操作,我应该向哪个 URL 发送发布请求?
例如,如果我想让用户登录 Google plus,我会点击这个 url
CURLOPT_URL => "https://www.googleapis.com/plus/v1/people/me?access_token=" . $access_token,
Gsuite 的网址是什么?
如果您的目标是在 G Suite 中检索有关用户的信息:
CURLOPT_URL => "https://www.googleapis.com/admin/directory/v1/users/john@example.com?access_token=" . $access_token;
注意:请查阅 Directory API 以了解如何执行委派。这是必需的。Domain-wide Delegation
正常访问令牌在未启用的情况下将不起作用。
您的凭据(访问令牌)将需要正确的范围:
https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.user
您的凭据将需要正确的委派。
Python 示例:
SCOPES = [
"https://www.googleapis.com/auth/admin.directory.group",
"https://www.googleapis.com/auth/admin.directory.user"
]
key_file = 'google-directory-api-service-account.json'
SERVICE_ACCOUNT_EMAIL = 'directory@development-123456.iam.gserviceaccount.com'
ADMIN_EMAIL = 'gsuite-admin@example.com'
credentials = service_account.Credentials.from_service_account_file(
key_file,
scopes = SCOPES)
credentials = credentials.with_subject(ADMIN_EMAIL)
有关我在设置 G Suite 访问权限时看到的常见错误,请参阅此答案的底部。
如果您的目标是检索存储在 Google OAuth 2.0 令牌中的信息:
这些 url 需要一个 Google OAuth 2.0 访问令牌。alt=json
指定返回 JSON 。
您可以在命令提示符下测试的示例:
curl -k "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ACCESS_TOKEN"
curl -k "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=ACCESS_TOKEN"
还有 v3 端点:
curl -k "https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=ACCESS_TOKEN"
设置对 G Suite 的 API 访问时的常见问题:
转到谷歌云控制台。为Admin SDK
.
您没有正确设置域范围的委派。
您尝试在现有服务帐户上设置域范围委派。您需要创建一个未分配任何 IAM 角色的新服务账户。