-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor reverse proxy for accessing WebAPIs #11
Comments
Hello, Probably link to this, it's possible to attach bearer in HTTP Client ? Custom handler ? Kr, |
@Hantse Hello Currently (package version But we are planning on changing this in version Blazor already provides some protection from cross-site scripting, but allowing the client part of your app unrestricted access to the user's JwtPair can still be dangerous. This issue here is about allowing authorized http requests without accessing the JwtPair on the client device. The idea is that the Server part of your Blazor app should provide a configurable reverse proxy for accessing necessary WebAPIs. In other words, it should act as a configurable middleware between the user and an external WebAPI that the user needs to access. It should also be doing necessary manipulations on the users' requests, like appending bearer tokens to the outbound part of the request. I suggest you to keep an eye on upcoming updates, especially regarding changes between We are doing this to ensure the extra safety of your users' data. Hope this brings some additional clarity on this aspect of the package. |
Hello ! Thx for feedback ! I've do that's as "workaround" : public class ApplicationAuthorizationMessageHandler(ICookieService cookieService)
: DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var token = await cookieService.GetAsync("AccessToken");
if (token != null)
{
request.Headers.TryAddWithoutValidation("Authorization", $"Bearer {token.Value}");
}
return await base.SendAsync(request, cancellationToken);
}
} But it's possible better : app.MapForwarder("/weather-forecast", "https://weatherapi", transformBuilder =>
{
transformBuilder.AddRequestTransform(async transformContext =>
{
var accessToken = await transformContext.HttpContext.GetTokenAsync("access_token");
transformContext.ProxyRequest.Headers.Authorization = new("Bearer", accessToken);
});
}).RequireAuthorization(); |
{host}/api
to arbitrary WebAPIs.The text was updated successfully, but these errors were encountered: