Add ContextWithToken (#1407)
* Add ContextWithToken * Tidying up BearerScheme Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
parent
1969a92b6e
commit
3ae8bc25f2
7
grpc.go
7
grpc.go
@ -11,6 +11,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/micro/go-micro/v2/auth"
|
||||||
"github.com/micro/go-micro/v2/broker"
|
"github.com/micro/go-micro/v2/broker"
|
||||||
"github.com/micro/go-micro/v2/client"
|
"github.com/micro/go-micro/v2/client"
|
||||||
"github.com/micro/go-micro/v2/client/selector"
|
"github.com/micro/go-micro/v2/client/selector"
|
||||||
@ -26,10 +27,6 @@ import (
|
|||||||
gmetadata "google.golang.org/grpc/metadata"
|
gmetadata "google.golang.org/grpc/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
BearerScheme = "Bearer "
|
|
||||||
)
|
|
||||||
|
|
||||||
type grpcClient struct {
|
type grpcClient struct {
|
||||||
opts client.Options
|
opts client.Options
|
||||||
pool *pool
|
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
|
// set the authorization token if one is saved locally
|
||||||
if len(header["authorization"]) == 0 {
|
if len(header["authorization"]) == 0 {
|
||||||
if token, err := config.Get("token"); err == nil && len(token) > 0 {
|
if token, err := config.Get("token"); err == nil && len(token) > 0 {
|
||||||
header["authorization"] = BearerScheme + token
|
header["authorization"] = auth.BearerScheme + token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user