google-admin-sdk - 使用 curl 对 Gsuite 用户进行身份验证的 URL 是什么?
问题描述
我想对 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 Directory API 之前未在项目 123456789012 中使用或已禁用。
转到谷歌云控制台。为Admin SDK
.
- 无权访问此资源/api。
您没有正确设置域范围的委派。
- 客户端未经授权无法使用此方法检索访问令牌
您尝试在现有服务帐户上设置域范围委派。您需要创建一个未分配任何 IAM 角色的新服务账户。
推荐阅读
- python - 在python中查找并检查行
- javascript - 无法在反应本机应用程序中清除 setInterval
- java - 错误:无法从静态上下文中引用非静态方法 LetConnect() Connection conn= LetConnect();
- reactjs - 如何在减速器中返回一个数组?
- java - 蓝牙服务器重启后 BLE 配对出现问题
- java - getConstructor 在 Java 中抛出 NoSuchMethodException
- javascript - 使用 react-native-navigation 导航到另一个屏幕
- python - 如何使用 tf.keras 加载模型?
- javascript - 无法在我的 ReactJs 项目中链接 Flaticons
- rest - kubernetes - 通过 REST-Call 列出所有命名空间的入口