callCredentials

Available in a dev version: 0․11․0-grpc-186

How to configure

Per-call authentication credentials to apply to this RPC.

Call credentials allow dynamic, per-request authentication by adding metadata headers such as bearer tokens, API keys, or custom authentication information.

Default Behavior

Defaults to GrpcEmptyCallCredentials, which attaches no authentication headers.

Usage Patterns

Setting in Client Interceptors

Call credentials can be dynamically added or modified in client interceptors:

val client = GrpcClient("example.com", 443) {
interceptors {
clientInterceptor {
callOptions.callCredentials += BearerTokenCredentials(getToken())
proceed(it)
}
}
}

Combining Multiple Credentials

Multiple call credentials can be combined using the + operator:

callOptions.callCredentials = bearerToken + apiKey
// or incrementally:
callOptions.callCredentials += additionalCredential

Transport Security

If any call credential requires transport security (GrpcCallCredentials.requiresTransportSecurity), the call will fail with kotlinx.rpc.grpc.GrpcStatusCode.UNAUTHENTICATED unless the channel is configured with TLS credentials (which is the default, except if the client uses plaintext()).

See also