我正在开发一项需要授权服务器才能连接到 Google 地图引擎的服务。
https://developers.google.com/maps-engine/documentation/oauth/serviceaccount和https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth?hl=en#service_account解释了如何做这个。
但是,在 Google API 中。NET,还没有 Google Maps Engine API 的服务类,那么我想参与库的部分流程,因为我不想做所有管理 JWT 的艰苦工作。
我认为是这样的:
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/mapsengine" }
}.FromCertificate(certificate));
var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/mapsengine/v1/projects");
credential.ApplyAuthenticationToRequest(request);
我想使用纯 HttpWebRequest,但是使用证书。
有人可以帮助我吗?
亚历克斯