Skip to content

Commit

Permalink
feat: add self signed jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed Jul 21, 2021
1 parent 6ad2188 commit 3b62ca3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
11 changes: 7 additions & 4 deletions google-cloud-kms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<site.installationModule>google-cloud-kms</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.27.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
Expand Down Expand Up @@ -53,10 +58,12 @@
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>1.67.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
<version>1.67.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
Expand All @@ -74,10 +81,6 @@
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-iam-v1</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public static List<String> getDefaultServiceScopes() {

/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES).setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.kms.v1;

import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse;

import com.google.common.collect.Lists;

import java.util.List;
import org.junit.Test;

public class sampleTest {

@Test
public void myTest() throws Exception {
KeyManagementServiceSettings settings = KeyManagementServiceSettings.newBuilder().setEndpoint("cloudkms.mtls.googleapis.com:443").build();
KeyManagementServiceClient client = KeyManagementServiceClient.create(settings);
String project = "projects/sijunliu-nondca-test/locations/global";

ListKeyRingsPagedResponse resp = client.listKeyRings(project);
List<KeyRing> resources = Lists.newArrayList(resp.iterateAll());
System.out.println(resources);
}
}

0 comments on commit 3b62ca3

Please sign in to comment.