How to add credentials authorization when using yarp reverse proxy

294 views Asked by At

I've successfully set up YARP as a reverse proxy, and it works well for routes that don't require authorization. However, I'm facing challenges when trying to include credentials for accessing destination APIs or sites. Can anyone guide me on how to manage this aspect with YARP?

This is what I tried before. But, it seems the credentials(HTTP_Authorization) is not working. I have userName and password, but don't know where to put it. And maybe it's not best to put it the userName and password on config files right?

  "ReverseProxy": {
    "Routes": {
      "route1": {
        "ClusterId": "cluster1",
        "Order": 1,
        "Match": {
          "Path": "/somePath/{**path1}"
        },
        "Transforms": [
          {
            "PathPattern": "/somePattern/{**path1}"
          }, 
          {
            "RequestHeader": "HTTP_Authorization",
            "Set": "Basic someAuthorizationHashKey"
          }
        ]
      },
    },
    "Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "https://someSitewithCredentials"
          }
        }
      },
    }
}   

Thank you

1

There are 1 answers

0
User12345 On BEST ANSWER

I have wrong request header. In IIS, the header is HTTP_Authorization. I thought it's same with yarp. But for yarp reverse proxy, it works with Authorization.

And for username and password, it reflects on someAuthorizationHashKey.

So, it's closed case