Is it possible to access request metadata in CallCredentials
My use case is that i want to perform custom logic inside my CallCredentials implementation based on the metadata set manually during request creation.
So when i execute my gRPC call like this:
var response = await someService.ExecuteSomeMethod(new RequestClass(), headers: new Metadata
{
{ "CustomData", "some data" }
});
I would like to access the "CustomData" inside the CallCredentials, like this:
internal static async Task InterceptAuthentication(AuthInterceptorContext _, Metadata metadata, IServiceProvider provider)
{
var myCustomData = metadata["CustomData"];
}
So far, the passed metadata is just empty and the documentation suggests that this is only for appending additional data. Right now i need to use very hacky AsyncLoca-based workaround for that. Is there a way to access the original metadata for the request here?
Could you use Grpc.Core.Interceptors.Interceptor instead? It is possible to read and modify context there.
I just moved from interceptor since I cannot perform await there and the official recommendation is to use CallCredentials. This whole design seems a bit weird
Having the same issue here.
I use a AddCallsCredentials to insert some custom logic for authentication: namely request a token exchange under certain conditions. Now I need to tweak such logic to perform the token exchange based on some request parameters.
I am also surprised that Interceptor doesn't support asynchronous operations and that the delegate used to create a CallCredentials uses the Metadata parameter as an output when it could have simply returned a Task<Metadata> to avoid ambiguity.