use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project workbench by all-of-us.
the class GenerateImpersonatedUserTokens method writeTokens.
private void writeTokens(String projectId, String[] usernames, String[] filenames) throws IOException {
final String saEmail = ServiceAccounts.getServiceAccountEmail(ADMIN_SERVICE_ACCOUNT_NAME, projectId);
final IamCredentialsClient credsClient = IamCredentialsClient.create();
final HttpTransport transport = new ApacheHttpTransport();
final Gson gson = new Gson();
for (int i = 0; i < usernames.length; i++) {
final String username = usernames[i];
final String filename = filenames[i];
log.info(String.format("Writing impersonated user credential for %s to %s", username, filename));
final DelegatedUserCredentials creds = new DelegatedUserCredentials(saEmail, username, FireCloudConfig.BILLING_SCOPES, credsClient, transport);
creds.refresh();
final String token = creds.getAccessToken().getTokenValue();
try (FileWriter w = new FileWriter(filename)) {
w.write(gson.toJson(ImmutableMap.of("created_at_epoch_seconds", Instant.now().getEpochSecond(), "token", token)));
}
}
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project workbench by all-of-us.
the class ImpersonatedServiceAccountApiClientFactory method getAccessToken.
public static String getAccessToken(String targetServiceAccount) throws IOException {
IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create();
String accessToken = iamCredentialsClient.generateAccessToken("projects/-/serviceAccounts/" + targetServiceAccount, Collections.EMPTY_LIST, Arrays.asList(FC_SCOPES), Duration.newBuilder().setSeconds(60 * 60).build()).getAccessToken();
return accessToken;
}
use of com.google.cloud.iam.credentials.v1.IamCredentialsClient 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.IamCredentialsClient 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.IamCredentialsClient in project gapic-generator-java by googleapis.
the class SyncGenerateAccessTokenStringListstringListstringDuration method syncGenerateAccessTokenStringListstringListstringDuration.
public static void syncGenerateAccessTokenStringListstringListstringDuration() 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<>();
List<String> scope = new ArrayList<>();
Duration lifetime = Duration.newBuilder().build();
GenerateAccessTokenResponse response = iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
}
}
Aggregations