1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-09-16 08:36:30 +02:00

Fix Auth Headers (#1324)

Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
ben-toogood
2020-03-10 16:47:01 +00:00
committed by GitHub
parent ed83c27f0e
commit 48b2a5c37c
3 changed files with 11 additions and 7 deletions

View File

@@ -123,7 +123,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
if md, ok := metadata.FromContext(ctx); ok {
header = make(map[string]string, len(md))
for k, v := range md {
header[k] = v
header[strings.ToLower(k)] = v
}
} else {
header = make(map[string]string)
@@ -133,9 +133,12 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout)
// set the content type for the request
header["x-content-type"] = req.ContentType()
// set the authorization token if one is saved locally
if token, err := config.Get("token"); err == nil && len(token) > 0 {
header["authorization"] = BearerScheme + token
if len(header["authorization"]) == 0 {
if token, err := config.Get("token"); err == nil && len(token) > 0 {
header["authorization"] = BearerScheme + token
}
}
md := gmetadata.New(header)