Search in sources :

Example 1 with ServiceAccountName

use of com.google.cloud.iam.credentials.v1.ServiceAccountName 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);
    }
}
Also used : SignJwtResponse(com.google.cloud.iam.credentials.v1.SignJwtResponse) ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName)

Example 2 with ServiceAccountName

use of com.google.cloud.iam.credentials.v1.ServiceAccountName in project gapic-generator-java by googleapis.

the class SyncGenerateIdTokenServiceaccountnameListstringStringBoolean method syncGenerateIdTokenServiceaccountnameListstringStringBoolean.

public static void syncGenerateIdTokenServiceaccountnameListstringStringBoolean() 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 audience = "audience975628804";
        boolean includeEmail = true;
        GenerateIdTokenResponse response = iamCredentialsClient.generateIdToken(name, delegates, audience, includeEmail);
    }
}
Also used : ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) GenerateIdTokenResponse(com.google.cloud.iam.credentials.v1.GenerateIdTokenResponse)

Example 3 with ServiceAccountName

use of com.google.cloud.iam.credentials.v1.ServiceAccountName in project gapic-generator-java by googleapis.

the class SyncSignBlobServiceaccountnameListstringBytestring method syncSignBlobServiceaccountnameListstringBytestring.

public static void syncSignBlobServiceaccountnameListstringBytestring() 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<>();
        ByteString payload = ByteString.EMPTY;
        SignBlobResponse response = iamCredentialsClient.signBlob(name, delegates, payload);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) ByteString(com.google.protobuf.ByteString) SignBlobResponse(com.google.cloud.iam.credentials.v1.SignBlobResponse)

Example 4 with ServiceAccountName

use of com.google.cloud.iam.credentials.v1.ServiceAccountName in project gapic-generator-java by googleapis.

the class SyncGenerateAccessTokenServiceaccountnameListstringListstringDuration method syncGenerateAccessTokenServiceaccountnameListstringListstringDuration.

public static void syncGenerateAccessTokenServiceaccountnameListstringListstringDuration() 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<>();
        List<String> scope = new ArrayList<>();
        Duration lifetime = Duration.newBuilder().build();
        GenerateAccessTokenResponse response = iamCredentialsClient.generateAccessToken(name, delegates, scope, lifetime);
    }
}
Also used : ArrayList(java.util.ArrayList) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) Duration(com.google.protobuf.Duration) GenerateAccessTokenResponse(com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse)

Example 5 with ServiceAccountName

use of com.google.cloud.iam.credentials.v1.ServiceAccountName in project spring-vault by spring-projects.

the class GcpIamCredentialsAuthentication method signJwt.

protected String signJwt() {
    String serviceAccount = getServiceAccountId();
    Map<String, Object> jwtPayload = getJwtPayload(this.options, serviceAccount);
    try {
        IamCredentialsSettings credentialsSettings = IamCredentialsSettings.newBuilder().setCredentialsProvider(() -> this.credentials).setTransportChannelProvider(this.transportChannelProvider).build();
        try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create(credentialsSettings)) {
            String payload = JSON_FACTORY.toString(jwtPayload);
            ServiceAccountName serviceAccountName = ServiceAccountName.of("-", serviceAccount);
            SignJwtResponse response = iamCredentialsClient.signJwt(serviceAccountName, Collections.emptyList(), payload);
            return response.getSignedJwt();
        }
    } catch (IOException e) {
        throw new VaultLoginException("Cannot sign JWT", e);
    }
}
Also used : SignJwtResponse(com.google.cloud.iam.credentials.v1.SignJwtResponse) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) IOException(java.io.IOException) IamCredentialsSettings(com.google.cloud.iam.credentials.v1.IamCredentialsSettings)

Aggregations

IamCredentialsClient (com.google.cloud.iam.credentials.v1.IamCredentialsClient)5 ServiceAccountName (com.google.cloud.iam.credentials.v1.ServiceAccountName)5 ArrayList (java.util.ArrayList)4 SignJwtResponse (com.google.cloud.iam.credentials.v1.SignJwtResponse)2 GenerateAccessTokenResponse (com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse)1 GenerateIdTokenResponse (com.google.cloud.iam.credentials.v1.GenerateIdTokenResponse)1 IamCredentialsSettings (com.google.cloud.iam.credentials.v1.IamCredentialsSettings)1 SignBlobResponse (com.google.cloud.iam.credentials.v1.SignBlobResponse)1 ByteString (com.google.protobuf.ByteString)1 Duration (com.google.protobuf.Duration)1 IOException (java.io.IOException)1