Google Cloud Platformサービスアカウントとキーファイルを使用して.NETでGoogleストレージにoauth-2接続を確立するにはどうすればよいですか?使用可能なサンプルとドキュメントではサービスアカウントについて扱われておらず、APIが混乱しており、頻繁に変更されるようであるため、既存のドキュメントは疑わしいものになります。重要なAPIの名前空間とバージョンを含む、実用的なコード例が最適です。Google Cloud Platformサービスアカウントとキーファイルを使用した.NETのGoogleストレージ
1
A
答えて
1
Cloud Storage JSON API documentationのコードサンプルでは、GOOGLE_APPLICATION_CREDENTIALSをダウンロードしたJSONキーを指すように設定した後、残念なことにApplication Default認証情報の使用についてのみ説明しています。
しかしあなたはクラウドストレージのドキュメントに与えられたCreateStorageClient()メソッドを適応させるために使用できるエクスポートP12キー、とのサービスアカウントを使用するためのdocumentation for the Google API Client Library for .NETのサンプルがあります:
public StorageService CreateStorageClient()
{
String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { StorageService.Scope.DevstorageFullControl }
}.FromCertificate(certificate));
var serviceInitializer = new BaseClientService.Initializer()
{
ApplicationName = "Storage Sample",
HttpClientInitializer = credential
};
return new StorageService(serviceInitializer);
}
同じ私は現在設定された.NETのdevの環境を持っていないが、それは一般的なアイデアを与える必要がありますように私はこれらをテストしていません
public StorageService CreateStorageClient()
{
GoogleCredential credential;
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(StorageService.Scope.DevstorageFullControl);
}
var serviceInitializer = new BaseClientService.Initializer()
{
ApplicationName = "Storage Sample",
HttpClientInitializer = credential
};
return new StorageService(serviceInitializer);
}
注:API docsに基づいて、直接JSONのキーを使用する方法使い方。 Cloud Storageドキュメントの更新をリクエストして、JSONキーを使用する例を追加します。
+0
私たちは根本的な問題を回避する方法を開発して以来、この解決方法を検証するまでには時間がかかるかもしれません。 –
関連する問題
- 1. Google Cloud Platformコンピュートエンジンストレージの使用
- 2. Google Cloud PlatformのサービスアカウントにREST APIを使用してロールを追加する
- 3. Google Cloud Platform - バックアップアップロード
- 4. Google Cloud Platformカスタムドメイン
- 5. Google Cloud Platformアクセステンソルボード
- 6. DNSとGoogle Cloud Platformのロードバランサ
- 7. Google Cloud Platformのアーキテクチャ
- 8. Google Cloudサービスアカウント 'roles/container.admin'
- 9. Google Cloud-PlatformでAdSenseを使用すると、Google Cloud PlatformでホストされたWebサイト
- 10. Google Cloud PlatformとMSSQL 2008
- 11. Google Cloud Platformとマルチゾーンの併用
- 12. Google Cloud Platform KVMサポート
- 13. Google Cloud Platform - SSH/Telnet
- 14. Google Cloud Platform with Firebase
- 15. Braintree Gateway - Google Cloud Platform
- 16. Google Cloud SQLストレージ
- 17. Mean Stack Google Cloud PlatformのRockMongo
- 18. Google Cloud Platformの無料トレイル
- 19. IOSのGoogle Cloud Platform OCR
- 20. Google Cloud Platformのアップグレード条件
- 21. Google Cloud Platform経由のテンソルボード
- 22. Google Cloud PlatformのQUICサポート
- 23. Google Cloud Powershell:サービスアカウントで認証
- 24. Google Cloud:ストレージとApp Engine
- 25. Bigrockドメインネームサーバー - Google Cloud Platform設定
- 26. Google Cloud Platform DataFlowワーカーIPアドレス
- 27. Google Cloud Platform - 統合ライブラリ
- 28. VMインスタンス言語Google Cloud Platform
- 29. Google SMTPサーバーとGoogle Appsサービスアカウントを使用したメール送信
- 30. Google Cloud Platformデプロイメントマネージャテンプレートを使用してバケットを作成する
あなたはDotNetOpenAuth /を見ましたか? https://github.com/DotNetOpenAuth/DotNetOpenAuth/wiki/Security-Scenarios – weismat
@weismat見てみましょう。今のところ私はコア・タスクを別の方法で解決しています。 Googleは.NET開発を容易にするインセンティブはありません。 –