twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
505 stars 80 forks source link

Is there exmaple using your proxy with JWT? I want to check the auth in the proxy like api gateway #107

Closed shalomda closed 5 months ago

twitchax commented 1 year ago

Currently, no, but you could suggest an example.

You likely want to use this example.

.WithBeforeSend((c, hrm) =>
        {
            // Set something that is needed for the downstream endpoint.
            hrm.Headers.Authorization = new AuthenticationHeaderValue("Basic");

            return Task.CompletedTask;
        })
vishalv26 commented 6 months ago

@twitchax how can we implement the above example?

basically i want to pass token with all the request something to compliment app.RunProxy(proxy => proxy.UseHttp("http://google.com")); In essence, I aim to forward all requests as they are, but with the addition of an authentication token. Could you please provide some suggestions or guidance on how to achieve this? Thank you

twitchax commented 6 months ago

Yep, basically, you use the example from the README. The way ASP.NET works is that you can do pretty much whatever you want with the context in here.

app.RunProxy(proxy => proxy
    .UseHttp((context, args) =>
    {
        // Check the auth token here by inspecting `context.Request.Headers` (or something like that).

        return "http://myhttpserver.com";
    });
vishalv26 commented 5 months ago

Thank you so much @twitchax 👯‍♂️