-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
35 lines (29 loc) · 896 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package grpc
import (
"github.com/alexfalkowski/auth/client"
"github.com/alexfalkowski/go-service/security/token"
gt "github.com/alexfalkowski/go-service/transport/grpc/security/token"
"google.golang.org/grpc"
)
// IsAuth for GRPC.
func IsAuth(c *token.Config) bool {
return c != nil && c.Kind == "auth"
}
// UnaryServerInterceptor for gRPC.
func UnaryServerInterceptor(cfg *token.Config, tkn *client.Token) []grpc.UnaryServerInterceptor {
if !IsAuth(cfg) {
return nil
}
return []grpc.UnaryServerInterceptor{
gt.UnaryServerInterceptor(tkn.Verifier("jwt", "konfig", "get-config")),
}
}
// StreamServerInterceptor for gRPC.
func StreamServerInterceptor(cfg *token.Config, tkn *client.Token) []grpc.StreamServerInterceptor {
if !IsAuth(cfg) {
return nil
}
return []grpc.StreamServerInterceptor{
gt.StreamServerInterceptor(tkn.Verifier("jwt", "konfig", "get-config")),
}
}