2016-07-13 3 views
1

Google Cloud Platform 서비스 계정 및 키 파일을 사용하여 .NET에서 Google 스토리지에 oauth-2 연결을 설정하는 방법은 무엇입니까? 사용 가능한 예제 및 설명서는 서비스 계정을 다루지 않으며 API가 혼란스럽고 자주 변경되는 것처럼 보이므로 기존의 설명서를 의심스럽게 만듭니다. 중요한 API 네임 스페이스 및 버전을 포함하여 작업 코드 예제가 가장 좋습니다.Google Cloud Platform 서비스 계정 및 키 파일을 사용하는 .NET의 Google 스토리지

+0

DotNetOpenAuth /? https://github.com/DotNetOpenAuth/DotNetOpenAuth/wiki/Security-desktop – weismat

+0

@weismat 살펴 보겠습니다. 지금은 다른 방식으로 핵심 과제를 해결하고 있습니다. Google은 .NET 개발을 쉽게 할 수있는 인센티브가 없습니다. –

답변

1

Cloud Storage JSON API documentation의 코드 샘플은 GOOGLE_APPLICATION_CREDENTIALS을 다운로드 한 JSON 키를 가리 키도록 설정 한 후에 Application Default 자격 증명을 사용하는 경우 만 다루고 있습니다.

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); 
} 

동일한에게 :

그러나 당신은 클라우드 스토리지의 문서에 주어진 CreateStorageClient() 메소드를 적용하는 데 사용할 수있는 수출 P12 키와 서비스 계정을 사용하기위한 documentation for the Google API Client Library for .NET에 샘플이 API docs에 따라 직접 JSON 키 사용 방법 : 나는 현재 .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); 
} 

참고 나는이 테스트를하지 않은,하지만 일반적인 아이디어를 줄 것이다 어떻게 작동하는지. Cloud Storage 문서에 대한 업데이트를 요청하여 JSON 키를 사용하는 예를 추가합니다.

+0

근본적인 문제에 대한 해결 방법을 개발 한 이래로이 솔루션을 검증하기까지는 다소 시간이 걸릴 수 있습니다. –

관련 문제