Ejemplo n.º 1
0
        public void JwtAccessToken_RestClient()
        {
            // See: https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth

            BigtableAdminService service = new BigtableAdminService(new BaseClientService.Initializer
            {
                HttpClientInitializer = Helper.GetServiceCredential().CreateScoped()
            });

            ListInstancesResponse response = service.Projects.Instances.List($"projects/{Helper.GetProjectId()}").Execute();

            Assert.NotNull(response);
        }
        public void JwtAccessToken_RestClient(bool useJwtAccessWithScopes, string[] scopes)
        {
            // See: https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth

            GoogleCredential credential = useJwtAccessWithScopes
                ? Helper.GetServiceCredentialWithJwtFlag().CreateScoped(scopes)
                : Helper.GetServiceCredential().CreateScoped(scopes);

            BigtableAdminService service = new BigtableAdminService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential
            });

            ListInstancesResponse response = service.Projects.Instances.List($"projects/{Helper.GetProjectId()}").Execute();

            Assert.NotNull(response);
        }
        public void JwtAccessToken_WrongScope_RestClient()
        {
            // See: https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth

            GoogleCredential credential = Helper.GetServiceCredentialWithJwtFlag().CreateScoped(new[] { "https://www.googleapis.com/auth/admob.readonly" });

            BigtableAdminService service = new BigtableAdminService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential
            });

            string expectedError = "Request had invalid authentication credentials.";

            var exception = Assert.Throws <GoogleApiException>(() =>
                                                               service.Projects.Instances.List($"projects/{Helper.GetProjectId()}").Execute());

            Assert.Contains(expectedError, exception.Message);
        }