Search in sources :

Example 6 with SignJwtResponse

use of com.google.cloud.iam.credentials.v1.SignJwtResponse 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

SignJwtResponse (com.google.cloud.iam.credentials.v1.SignJwtResponse)6 IamCredentialsClient (com.google.cloud.iam.credentials.v1.IamCredentialsClient)5 SignJwtRequest (com.google.cloud.iam.credentials.v1.SignJwtRequest)3 ServiceAccountName (com.google.cloud.iam.credentials.v1.ServiceAccountName)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GrpcTransportChannel (com.google.api.gax.grpc.GrpcTransportChannel)1 FixedTransportChannelProvider (com.google.api.gax.rpc.FixedTransportChannelProvider)1 AccessToken (com.google.auth.oauth2.AccessToken)1 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 IamCredentialsSettings (com.google.cloud.iam.credentials.v1.IamCredentialsSettings)1 ManagedChannel (io.grpc.ManagedChannel)1 MethodDescriptor (io.grpc.MethodDescriptor)1 Server (io.grpc.Server)1 ServerServiceDefinition (io.grpc.ServerServiceDefinition)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 ProtoLiteUtils (io.grpc.protobuf.lite.ProtoLiteUtils)1 ServerCalls (io.grpc.stub.ServerCalls)1 ServerCalls.asyncUnaryCall (io.grpc.stub.ServerCalls.asyncUnaryCall)1