aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Auth/GoogleCredential.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Auth/GoogleCredential.cs')
-rw-r--r--src/csharp/Grpc.Auth/GoogleCredential.cs21
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;
- }
}
}