Reputation: 33
I am using Armeria with gRPC/java and I'm looking to decorate one of the services with an AuthService like this https://sultanov.dev/blog/securing-java-grpc-services-with-jwt-based-authentication/. I want to access the gRPC request header, do some validation, and if validated, write something in the context object and proceed.
I am having some trouble finding documentation for how to interact with the context object correctly. Can someone help point me in the right direction? Thanks!
Upvotes: 1
Views: 1009
Reputation: 111
You can use an Armeria decorator to intercept the call and validate it: https://armeria.dev/docs/server-decorator#extending-simpledecoratinghttpservice-and-simpledecoratingrpcservice
It's beneficial when you need to make another asynchronous call in the intercepting logic because it's not easy to do that with a gRPC interceptor.
You can write something to RequestContext
in the decorator.
https://armeria.dev/docs/advanced-custom-attributes#requestcontext-custom-attributes
You can retrieve it in your service via RequestContext.current()
later.
Upvotes: 3