mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 17:22:26 +00:00
add metadata interceptors, auth client interceptors
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@ -4,6 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
|
||||
"go.linka.cloud/grpc/interceptors"
|
||||
"go.linka.cloud/grpc/interceptors/metadata"
|
||||
)
|
||||
|
||||
type TokenValidator func(ctx context.Context, token string) (context.Context, error)
|
||||
@ -17,3 +20,7 @@ func makeTokenAuthFunc(v TokenValidator) grpc_auth.AuthFunc {
|
||||
return v(ctx, a)
|
||||
}
|
||||
}
|
||||
|
||||
func NewBearerClientInterceptors(token string) interceptors.ClientInterceptors {
|
||||
return metadata.NewInterceptors("authorization", "Bearer "+token)
|
||||
}
|
||||
|
Reference in New Issue
Block a user