Interceptor trait should support async functions.
tonic
I would like to write an authentication interceptor which needs to make API calls to validate the incoming request, and it would be great if these could be async.
@matthauck do these API calls need to happen on _each_ request or is this a case of refreshing a token? The reason I ask is because intentionally inteceptors were designed to not be async to make them simpler. We still provide the ability to use tower layers to intercept the whole HTTP2 request.
Yeah, something like validating an incoming token. Not necessarily every request, but potentially I suppose? Will look into intercepting at the tower layer.
So one suggestion is to actually use something from the arc-swap crate and spawn a background task to refresh a token. If you don't need to do some specific of async work per request, this method works well and its totally fine to load the arcswap in the sync interceptor fn.
Okay, great. thanks! we can close this issue then. "by design" :)
Are the async interceptors still open for consideration at some point (e.g. enough people request the feature)? I'd also like to be able to perform API calls (need to be immediate, so background call does not suffice).
@blaind yes, it will be done via tower. I have not had much time to explore this but should hopefully soon :)
Most helpful comment
@blaind yes, it will be done via tower. I have not had much time to explore this but should hopefully soon :)