1

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!

Chan Rao
  • 33
  • 3

2 Answers2

2

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.

minwoox
  • 101
  • 4
  • Thanks, this worked! Extended `SimpleDecoratingHttpService` and used that to decorate my gRPC services – Chan Rao Jul 06 '22 at 17:13
1

Check this out. This shows how to get the JWT from the metadata (request header) and set some value into the context accordingly.

San P
  • 494
  • 3
  • 7
  • Seems that this context is not working with Armeria, but I'll keep this in mind next time I'm building something without Armeria, thanks! – Chan Rao Jun 30 '22 at 20:49