use of com.google.cloud.iam.credentials.v1.SignJwtResponse in project gapic-generator-java by googleapis.
the class SyncSignJwtServiceaccountnameListstringString method syncSignJwtServiceaccountnameListstringString.
public static void syncSignJwtServiceaccountnameListstringString() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
ServiceAccountName name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]");
List<String> delegates = new ArrayList<>();
String payload = "payload-786701938";
SignJwtResponse response = iamCredentialsClient.signJwt(name, delegates, payload);
}
}
use of com.google.cloud.iam.credentials.v1.SignJwtResponse in project spring-vault by spring-projects.
the class GcpIamCredentialsAuthenticationUnitTests method shouldLogin.
@Test
void shouldLogin() {
this.serverCall = ((request, responseObserver) -> {
SignJwtResponse signJwtResponse = SignJwtResponse.newBuilder().setSignedJwt("my-jwt").setKeyId("key-id").build();
responseObserver.onNext(signJwtResponse);
responseObserver.onCompleted();
});
this.mockRest.expect(requestTo("/auth/gcp/login")).andExpect(method(HttpMethod.POST)).andExpect(jsonPath("$.role").value("dev-role")).andExpect(jsonPath("$.jwt").value("my-jwt")).andRespond(withSuccess().contentType(MediaType.APPLICATION_JSON).body("{" + "\"auth\":{\"client_token\":\"my-token\", \"renewable\": true, \"lease_duration\": 10}" + "}"));
PrivateKey privateKeyMock = mock(PrivateKey.class);
ServiceAccountCredentials credential = (ServiceAccountCredentials) ServiceAccountCredentials.newBuilder().setClientEmail("hello@world").setProjectId("foobar").setPrivateKey(privateKeyMock).setPrivateKeyId("key-id").setAccessToken(new AccessToken("foobar", Date.from(Instant.now().plus(1, ChronoUnit.DAYS)))).build();
GcpIamCredentialsAuthenticationOptions options = GcpIamCredentialsAuthenticationOptions.builder().role("dev-role").credentials(credential).build();
GcpIamCredentialsAuthentication authentication = new GcpIamCredentialsAuthentication(options, this.restTemplate, FixedTransportChannelProvider.create(GrpcTransportChannel.create(managedChannel)));
VaultToken login = authentication.login();
assertThat(login).isInstanceOf(LoginToken.class);
assertThat(login.getToken()).isEqualTo("my-token");
LoginToken loginToken = (LoginToken) login;
assertThat(loginToken.isRenewable()).isTrue();
assertThat(loginToken.getLeaseDuration()).isEqualTo(Duration.ofSeconds(10));
}
use of com.google.cloud.iam.credentials.v1.SignJwtResponse in project gapic-generator-java by googleapis.
the class SyncSignJwt method syncSignJwt.
public static void syncSignJwt() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
SignJwtRequest request = SignJwtRequest.newBuilder().setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString()).addAllDelegates(new ArrayList<String>()).setPayload("payload-786701938").build();
SignJwtResponse response = iamCredentialsClient.signJwt(request);
}
}
use of com.google.cloud.iam.credentials.v1.SignJwtResponse in project gapic-generator-java by googleapis.
the class SyncSignJwtStringListstringString method syncSignJwtStringListstringString.
public static void syncSignJwtStringListstringString() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
String name = ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString();
List<String> delegates = new ArrayList<>();
String payload = "payload-786701938";
SignJwtResponse response = iamCredentialsClient.signJwt(name, delegates, payload);
}
}
use of com.google.cloud.iam.credentials.v1.SignJwtResponse in project gapic-generator-java by googleapis.
the class AsyncSignJwt method asyncSignJwt.
public static void asyncSignJwt() throws Exception {
// It may require modifications to work in your environment.
try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create()) {
SignJwtRequest request = SignJwtRequest.newBuilder().setName(ServiceAccountName.of("[PROJECT]", "[SERVICE_ACCOUNT]").toString()).addAllDelegates(new ArrayList<String>()).setPayload("payload-786701938").build();
ApiFuture<SignJwtResponse> future = iamCredentialsClient.signJwtCallable().futureCall(request);
// Do something.
SignJwtResponse response = future.get();
}
}
Aggregations