From bea7cbd9a565a853e5147a8f4e42a91376e3e52d Mon Sep 17 00:00:00 2001
From: Jan Tattermusch <jtattermusch@google.com>
Date: Fri, 4 Sep 2015 14:08:19 -0700
Subject: [PATCH] use service account credentials for per RPC test

---
 src/csharp/Grpc.IntegrationTesting/InteropClient.cs | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 34d5157d3e..0884c6ea60 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -166,7 +166,7 @@ namespace Grpc.IntegrationTesting
                     await RunOAuth2AuthTokenAsync(client, options.DefaultServiceAccount, options.OAuthScope);
                     break;
                 case "per_rpc_creds":
-                    await RunPerRpcCredsAsync(client, options.DefaultServiceAccount);
+                    await RunPerRpcCredsAsync(client, options.DefaultServiceAccount, options.OAuthScope);
                     break;
                 case "cancel_after_begin":
                     await RunCancelAfterBeginAsync(client);
@@ -391,14 +391,11 @@ namespace Grpc.IntegrationTesting
             Console.WriteLine("Passed!");
         }
 
-        public static async Task RunPerRpcCredsAsync(TestService.TestServiceClient client, string defaultServiceAccount)
+        public static async Task RunPerRpcCredsAsync(TestService.TestServiceClient client, string defaultServiceAccount, string oauthScope)
         {
             Console.WriteLine("running per_rpc_creds");
-
-            ITokenAccess credential = await GoogleCredential.GetApplicationDefaultAsync();
-            // TODO: currently there's no way how to obtain AuthURI for JWT per-rpc creds.
-            string authUri = "https://grpc-test.sandbox.google.com/grpc.testing.TestService";
-            string accessToken = await credential.GetAccessTokenForRequestAsync(authUri);
+            ITokenAccess credential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { oauthScope });
+            string accessToken = await credential.GetAccessTokenForRequestAsync();
             var headerInterceptor = AuthInterceptors.FromAccessToken(accessToken);
 
             var request = new SimpleRequest
-- 
GitLab