Beispiel #1
0
        public static async Task RunOAuth2AuthTokenAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running oauth2_auth_token");
            ITokenAccess credential  = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { AuthScope });
            string       oauth2Token = await credential.GetAccessTokenForRequestAsync();

            client.HeaderInterceptor = AuthInterceptors.FromAccessToken(oauth2Token);

            var request = SimpleRequest.CreateBuilder()
                          .SetFillUsername(true)
                          .SetFillOauthScope(true)
                          .Build();

            var response = client.UnaryCall(request);

            Assert.AreEqual(AuthScopeResponse, response.OauthScope);
            Assert.AreEqual(ServiceAccountUser, response.Username);
            Console.WriteLine("Passed!");
        }
Beispiel #2
0
        public static async Task RunPerRpcCredsAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running per_rpc_creds");

            ITokenAccess credential  = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { AuthScope });
            string       oauth2Token = await credential.GetAccessTokenForRequestAsync();

            var headerInterceptor = AuthInterceptors.FromAccessToken(oauth2Token);

            var request = new SimpleRequest
            {
                FillUsername   = true,
                FillOauthScope = true
            };

            var headers = new Metadata();

            headerInterceptor(null, "", headers);
            var response = client.UnaryCall(request, headers: headers);

            Assert.AreEqual(AuthScopeResponse, response.OauthScope);
            Assert.AreEqual(ServiceAccountUser, response.Username);
            Console.WriteLine("Passed!");
        }