From 3ae8bc25f29390f4f1762035cb7333949704eeb6 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 11:20:53 +0000 Subject: [PATCH] Add ContextWithToken (#1407) * Add ContextWithToken * Tidying up BearerScheme Co-authored-by: Ben Toogood --- grpc.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/grpc.go b/grpc.go index 432ef53..0357abc 100644 --- a/grpc.go +++ b/grpc.go @@ -11,6 +11,7 @@ import ( "sync/atomic" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -26,10 +27,6 @@ import ( gmetadata "google.golang.org/grpc/metadata" ) -var ( - BearerScheme = "Bearer " -) - type grpcClient struct { opts client.Options pool *pool @@ -137,7 +134,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the authorization token if one is saved locally if len(header["authorization"]) == 0 { if token, err := config.Get("token"); err == nil && len(token) > 0 { - header["authorization"] = BearerScheme + token + header["authorization"] = auth.BearerScheme + token } }