CallCredentialsHelper
or create the CallCredentials
and StubTransformer
s
yourself.@Deprecated public final class AuthenticatingClientInterceptors extends Object
CallCredentials
and the necessary ClientInterceptor
s.
This class can be used like this:
@Bean
CallCredentials grpcCallCredentials() {
// Note: This method uses experimental grpc-java-API features.
return CallCredentialsHelper.basicAuthCallCredentials("foo", "bar");
// return CallCredentialsHelper.requirePrivacy(...); // Always a good idea
}
@Bean
ClientInterceptor grpcCallCredentialsInterceptor() {
return AuthenticatingClientInterceptors.callCredentialsInterceptor(grpcCallCredentials());
}
Note: You don't need extra call credentials if you authenticate yourself via certificates.
@Bean
public GlobalClientInterceptorConfigurer basicAuthInterceptorConfigurer() {
return registry -> registry.addClientInterceptors(grpcCallCredentialsInterceptor());
}
GrpcClient.interceptorNames()
field to add a bean by name.
@GrpcClient(value = "testChannel", interceptorNames = "grpcCallCredentialsInterceptorForTest")
private Channel testChannel;
Modifier and Type | Method and Description |
---|---|
static ClientInterceptor |
basicAuthInterceptor(String username,
String password)
Deprecated.
Use the (potentially) more secure
CallCredentials . |
static ClientInterceptor |
bearerAuth(String token)
Deprecated.
Use
StubTransformer s to set the credentials directly on AbstractStub s. |
static ClientInterceptor |
callCredentialsInterceptor(CallCredentials callCredentials)
Deprecated.
Use
StubTransformer s to set the credentials directly on AbstractStub s. |
@Deprecated public static ClientInterceptor basicAuthInterceptor(String username, String password)
CallCredentials
.ClientInterceptor
that adds the given username and passwords as basic auth to all requests.
The header will be encoded with UTF_8
.username
- The username to use.password
- The password to use.CallCredentialsHelper.encodeBasicAuth(String, String)
@Deprecated public static ClientInterceptor callCredentialsInterceptor(CallCredentials callCredentials)
StubTransformer
s to set the credentials directly on AbstractStub
s.ClientInterceptor
that will attach the given call credentials to the given call. This is an
alternative to manually configuring the stubs using AbstractStub.withCallCredentials(CallCredentials)
.callCredentials
- The call credentials to attach.Basic-Auth
@Deprecated public static ClientInterceptor bearerAuth(String token)
StubTransformer
s to set the credentials directly on AbstractStub
s.ClientInterceptor
that adds the given bearer token as Bearer Authentication to all
requests. The header will be encoded with UTF_8
.token
- the bearer token