mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 17:22:26 +00:00
add auth interceptors
This commit is contained in:
19
interceptors/auth/token.go
Normal file
19
interceptors/auth/token.go
Normal file
@ -0,0 +1,19 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
)
|
||||
|
||||
type TokenValidator func(ctx context.Context, token string) (context.Context, error)
|
||||
|
||||
func makeTokenAuthFunc(v TokenValidator) grpc_auth.AuthFunc {
|
||||
return func(ctx context.Context) (context.Context, error) {
|
||||
a, err := grpc_auth.AuthFromMD(ctx, "bearer")
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
return v(ctx, a)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user