-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Unauthorized status] Accessing Remote APIs via Simple HTTP Forwarder in BFF Configuration #1511
Comments
Based on your configuration, you are using BFF in your server-side program.cs therefore you must add the anti-forgery header configured whenever you are calling the endpoints that were setup. For what I can tell this is the issue. Can we see your AntiForgeryHandler class? GET /endpoint x-csrf: 1 |
The below is AntiforgeryHandler.cs in the client-side public class AntiforgeryHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.Add("X-CSRF", "1");
return base.SendAsync(request, cancellationToken);
}
} Are you suggesting that I should also use the "anti-forgery header" in the server-side as well? Is yes, what is the best way to use "anti-forgery header" with REMOTE api? Thank you. |
Thanks you for the code snippet. The "anti-forgery headers" are for the client side code. Do you still get the error if you append "SkipAntiforgery()" app.MapRemoteBffApiEndpoint("/api/bookings", "https://localhost:5001")
.RequireAccessToken(Duende.Bff.TokenType.User)
.SkipAntiforgery(); to the server-side endpoints? If you are still getting the error you can rule out the Antiforgery handler and focus on the API setup. In my API code, I usually set my schemes in the AddAuthentication and AddJwtBearer calls. Can you try this? builder.Services.AddAuthentication("token")
.AddJwtBearer("token", options =>
{
// Configure the Authority to the expected value for
// the authentication provider. This ensures the token
// is appropriately validated.
options.Authority ="https://localhost:5001";
options.TokenValidationParameters.ValidateAudience = false;
});
builder.Services.AddAuthorization(); |
Unfortunately, I tried both recommendations, but the errors still persist. Interestingly, I also have a standalone WASM client with a similar setup, and it works fine. |
So what are the differences as you see them? I'm curious |
In addition:
|
@amiriltd @RolandGuijt apologies for the delayed response. I will create a minimal repository to reproduce the issue ASAP. |
Which version of Duende BFF are you using?
2.2.0
Which version of .NET are you using?
net9.0
Describe the bug
Unauthorized error when making API calls from a Blazor WebAssembly Hosted application (with both server and client projects) to an API Project. Here's a summary of my setup:
What works:
The issue:
To Reproduce
Config.cs
Client-side Program.cs
Server-side Program.cs
Program.cs
Expected behavior
API calls from the Blazor WebAssembly Hosted app should be authenticated successfully, and the API Project should respond without returning an Unauthorized error.
Could you please provide guidance on what might be causing this issue or any potential misconfigurations?
The text was updated successfully, but these errors were encountered: