I am using github.com/grpc-ecosystem/go-grpc-middleware/util/metautils
package for extracting the header, seeing Link to AuthFromMD implementation I am sure that I can override AuthFromMD and have my own Header name instead of authorization
. But turns out to be var:=metautils.ExtractIncoming(ctx).Get(headerAuthorize)
this method call is always expecting the headerAuthorize
to be authorization
. Or it is throwing error. My use case is to have different HeaderNames so I can resolve multiple Headers using this method. Can some one please help me
The issue is AuthFromMD is using context.Context
in GRPC-Gateway. So Any request to grpc through the gateway is passing through this and the context is dropping any of the headers which is not in the METADATA defined in the context of this package.
Solution would be overriding this, and adding any of the custom headers to be not dropped from the Context
You are correct that AuthFromMD
expects the header to be named authorization
. This is in part because it mimics the HTTP header authorization
which is always named the same.
I'm not sure that I understand your use case, but you can definitely reimplement AuthFromMD
in your own package and modify it to take a header name.