1

YARP-based service(just YARP) proxies a request to Service1. And what is important YARP authenticates on Service1. What is the best way to implement token refresh (see scheme)? In middleware? Another way? Would be grateful for an example.

scheme

I tried to do something like this:

endpoints.MapReverseProxy(proxyPipeline =>
{
    proxyPipeline.Use((context, next) =>
    {
      await _next(context);

      if (context.Response.StatusCode == StatusCodes.Status401Unauthorized)
      {
        // requset NEW_Yarp-Service1_Token on Service1
        // set "Bearer NEW_Yarp-Service1_Token" to Header

        await _next(context);
      }
    });
    proxyPipeline.UseSessionAffinity();
    proxyPipeline.UseLoadBalancing();
    proxyPipeline.UsePassiveHealthChecks();
}); 

This leads to 502 Bad Gateway.

Andrey
  • 11
  • 2
  • Hi Andrey , is this issue already resolved ? Why you are not able to call token refresh endpoint as would call it otherwise. My experience is if you have {*catch--all} route in YARP config it wont pass on querystring params correctly , so we had to inject those query string params as CustomRequest headers – Sagar Aug 26 '23 at 04:15

0 Answers0