我使用 Google 目录 API 已经有一段时间了。
但是,我需要在 Google 的管理设置部分更新 SSO 设置。是的,他们说它会在某个时候被弃用,但根据谷歌员工的说法,在新的 API 可用之前需要一段时间,然后旧的 API 将被删除。
首先,如果那里有 NUGET 包,请告诉我。我似乎找不到任何适用于管理设置 API 的东西:https ://developers.google.com/admin-sdk/admin-settings/
我的第一次尝试是在 Google 中获取 SSO 设置。
我可以使用邮递员来提取这些信息,这样我就知道 API 有效。
但是,我遇到了两个问题:
- 如何使用我在 apis.google.directory 类中使用的服务证书进行身份验证?
- 期待,我如何请求访问管理设置?在目录 API 中,我有范围枚举可供选择。如果我要手动连接到 API,我认为我需要手动调用它?
代码
var certificate = new X509Certificate2(serviceAccountCertPath,
serviceAccountCertPassword,
X509KeyStorageFlags.Exportable);
// below the scopes are going to get in my way, right? What is the scope process I need to do for this manually?
credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser,
DirectoryService.Scope.AdminDirectoryGroup,
DirectoryService.Scope.AdminDirectoryOrgunit},
User = _szAdminEmail
}.FromCertificate(certificate));
// I'm not seeing anyway to call the above credentials
using (HttpClient client = new HttpClient())
{
// client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
client.BaseAddress = new Uri(@"https://apps-apis.google.com/a/feeds/domain/2.0/[mydomain]/sso/general");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//client.DefaultRequestHeaders.
HttpResponseMessage response = client.GetAsync("api/Values").Result; // Blocking call!
var products = response.Content.ReadAsStringAsync().Result;
return products.ToString();
}