diff options
author | 2015-07-26 12:55:47 -0700 | |
---|---|---|
committer | 2015-07-26 12:55:47 -0700 | |
commit | d9aed1d0103122c235c5577f7a00ead9cbc1a7b9 (patch) | |
tree | c28b50ccab7a19287984857daf40d552e50247ab /src/csharp/Grpc.Auth/GoogleCredential.cs | |
parent | 7cb085375581ff2b18865e4e72b335276d08d09d (diff) | |
parent | 5c575dd6e4b01cd68cca5d1917b58023dcf4ca0f (diff) |
Merge github.com:grpc/grpc into elliptic-orange-chamelion
Conflicts:
src/csharp/ext/grpc_csharp_ext.c
Diffstat (limited to 'src/csharp/Grpc.Auth/GoogleCredential.cs')
-rw-r--r-- | src/csharp/Grpc.Auth/GoogleCredential.cs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/csharp/Grpc.Auth/GoogleCredential.cs b/src/csharp/Grpc.Auth/GoogleCredential.cs index 7edf19ed67..9936cf583c 100644 --- a/src/csharp/Grpc.Auth/GoogleCredential.cs +++ b/src/csharp/Grpc.Auth/GoogleCredential.cs @@ -89,17 +89,15 @@ namespace Grpc.Auth return new GoogleCredential(new ComputeCredential(new ComputeCredential.Initializer())); } - JObject o1 = JObject.Parse(File.ReadAllText(credsPath)); - string clientEmail = o1.GetValue(ClientEmailFieldName).Value<string>(); - string privateKeyString = o1.GetValue(PrivateKeyFieldName).Value<string>(); - var privateKey = ParsePrivateKeyFromString(privateKeyString); + JObject jsonCredentialParameters = JObject.Parse(File.ReadAllText(credsPath)); + string clientEmail = jsonCredentialParameters.GetValue(ClientEmailFieldName).Value<string>(); + string privateKeyString = jsonCredentialParameters.GetValue(PrivateKeyFieldName).Value<string>(); var serviceCredential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(clientEmail) { Scopes = scopes, - Key = privateKey - }); + }.FromPrivateKey(privateKeyString)); return new GoogleCredential(serviceCredential); } @@ -123,16 +121,5 @@ namespace Grpc.Auth return credential; } } - - private RSACryptoServiceProvider ParsePrivateKeyFromString(string base64PrivateKey) - { - // TODO(jtattermusch): temporary code to create RSACryptoServiceProvider. - base64PrivateKey = base64PrivateKey.Replace("-----BEGIN PRIVATE KEY-----", "").Replace("\n", "").Replace("-----END PRIVATE KEY-----", ""); - RsaPrivateCrtKeyParameters key = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(base64PrivateKey)); - RSAParameters rsaParameters = DotNetUtilities.ToRSAParameters(key); - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.ImportParameters(rsaParameters); - return rsa; - } } } |