Skip to content

Commit

Permalink
Add shortcut to set API key (#2052)
Browse files Browse the repository at this point in the history
Add shortcut to set API key
  • Loading branch information
Quinn-With-Two-Ns authored May 23, 2024
1 parent 5ccb859 commit 5e5cf0b
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.uber.m3.tally.Scope;
import io.grpc.*;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import io.temporal.authorization.AuthorizationGrpcMetadataProvider;
import io.temporal.authorization.AuthorizationTokenSupplier;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -508,6 +510,23 @@ public T addGrpcMetadataProvider(GrpcMetadataProvider grpcMetadataProvider) {
return self();
}

/**
* Add a {@link AuthorizationGrpcMetadataProvider} to the gRPC metadata providers that supplies
* an authentication token on each gRPC request.
*
* @param apiKey authentication token supplier to be called on each gRPC request. SDK will
* automatically add the "Bearer " prefix.
* @return {@code this}
*/
public T addApiKey(AuthorizationTokenSupplier apiKey) {
addGrpcMetadataProvider(
new AuthorizationGrpcMetadataProvider(
() -> {
return "Bearer " + apiKey.supply();
}));
return self();
}

/**
* @param grpcMetadataProviders gRPC metadata/headers providers to be called on each gRPC
* request to supply additional headers
Expand Down

0 comments on commit 5e5cf0b

Please sign in to comment.