私はかなり長い間、Google ディレクトリ API を使用してきました。
ただし、Google の管理者設定セクションで SSO 設定を更新する必要があります。はい、ある時点で非推奨になると言われていますが、Google の従業員によると、新しい API が利用可能になるまでにはしばらく時間がかかり、その後古い API は削除されます。
まず、NUGET パッケージが公開されている場合はお知らせください。管理者設定 API で動作するものが見つからないようです: https://developers.google.com/admin-sdk/admin-settings/
私の最初の試みは、Google で SSO 設定を取得することです。
郵便配達員を使用してこの情報を取得できるので、API が機能することがわかります。
ただし、次の 2 つの問題が発生しています。
- 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();
}