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:
@ -8,13 +8,15 @@ import (
|
||||
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
|
||||
"go.linka.cloud/grpc/errors"
|
||||
"go.linka.cloud/grpc/interceptors"
|
||||
"go.linka.cloud/grpc/interceptors/metadata"
|
||||
)
|
||||
|
||||
func BasicAuth(user, password string) string {
|
||||
return "basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+password))
|
||||
}
|
||||
|
||||
type BasicValidator func(ctx context.Context, user, password string) (context.Context,error)
|
||||
type BasicValidator func(ctx context.Context, user, password string) (context.Context, error)
|
||||
|
||||
func makeBasicAuthFunc(v BasicValidator) grpc_auth.AuthFunc {
|
||||
return func(ctx context.Context) (context.Context, error) {
|
||||
@ -34,3 +36,7 @@ func makeBasicAuthFunc(v BasicValidator) grpc_auth.AuthFunc {
|
||||
return v(ctx, cs[:s], cs[s+1:])
|
||||
}
|
||||
}
|
||||
|
||||
func NewBasicAuthClientIntereptors(user, password string) interceptors.ClientInterceptors {
|
||||
return metadata.NewInterceptors("authorization", BasicAuth(user, password))
|
||||
}
|
||||
|
Reference in New Issue
Block a user