Add ContextWithToken (#1407)

* Add ContextWithToken

* Tidying up BearerScheme

Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
ben-toogood 2020-03-25 11:20:53 +00:00 committed by Vasiliy Tolstov
parent 1969a92b6e
commit 3ae8bc25f2

View File

@ -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
}
}