From 36386354d72e9d6ea72631a09bbbd810a5724c3c Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 13:51:32 +0100 Subject: [PATCH] Fallback to service token --- client/grpc/grpc.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 8cd55dd8..5f14c25d 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -131,11 +131,14 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // if the caller specifies using service privelages, and the client - // has auth set, override the authorization header - if opts.ServiceToken && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { - t := g.opts.Auth.Options().Token - header["authorization"] = auth.BearerScheme + t.Token + // if the caller specifies using service token or no token + // was passed with the request, set the service token + var srvToken string + if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + srvToken = g.opts.Auth.Options().Token.Token + } + if (opts.ServiceToken || len(header["authorization"]) == 0) && len(srvToken) > 0 { + header["authorization"] = auth.BearerScheme + srvToken } // fall back to using the authorization token set in config,