I work on go grpc service and implementing authorization. Literally, have to allow or forbid access to gprc methods base on JWT claims.
I do JWT parsing on grpc.UnaryServerInterceptor
level - extracting claims and populate context with value, unauthenticated if there is no jwt or it is incorrect.
func (s *Server) GetSomething(ctx context.Context, req *GetSomething Request) (*GetSomething Response, error) {
if hasAccessTo(ctx, req.ID) {
//some work here
}
}
func hasAccessTo(ctx context.Context, string id) {
value := ctx.Value(ctxKey).(MyStruct)
//some work here
}
So I wonder if there is some common practice for authorization/authentication to avoid boilerplate code in each grpc server method?