Skip to content

Commit 5e5cf0b

Browse files
Add shortcut to set API key (#2052)
Add shortcut to set API key
1 parent 5ccb859 commit 5e5cf0b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

temporal-serviceclient/src/main/java/io/temporal/serviceclient/ServiceStubsOptions.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.uber.m3.tally.Scope;
2626
import io.grpc.*;
2727
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
28+
import io.temporal.authorization.AuthorizationGrpcMetadataProvider;
29+
import io.temporal.authorization.AuthorizationTokenSupplier;
2830
import java.time.Duration;
2931
import java.util.ArrayList;
3032
import java.util.Collection;
@@ -508,6 +510,23 @@ public T addGrpcMetadataProvider(GrpcMetadataProvider grpcMetadataProvider) {
508510
return self();
509511
}
510512

513+
/**
514+
* Add a {@link AuthorizationGrpcMetadataProvider} to the gRPC metadata providers that supplies
515+
* an authentication token on each gRPC request.
516+
*
517+
* @param apiKey authentication token supplier to be called on each gRPC request. SDK will
518+
* automatically add the "Bearer " prefix.
519+
* @return {@code this}
520+
*/
521+
public T addApiKey(AuthorizationTokenSupplier apiKey) {
522+
addGrpcMetadataProvider(
523+
new AuthorizationGrpcMetadataProvider(
524+
() -> {
525+
return "Bearer " + apiKey.supply();
526+
}));
527+
return self();
528+
}
529+
511530
/**
512531
* @param grpcMetadataProviders gRPC metadata/headers providers to be called on each gRPC
513532
* request to supply additional headers

0 commit comments

Comments
 (0)