add auth interceptors

This commit is contained in:
2021-12-13 12:08:10 +01:00
parent 55251b5020
commit e578d62a29
6 changed files with 400 additions and 0 deletions

View 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)
}
}