Closed jkdba closed 2 years ago
The BFF framework does not make sense for Blazor Server since you are already on the server. You need to treat that more like a traditional MVC style application with server-side controllers.
Really the only useful part here would be the token management - which comes from https://github.com/IdentityModel/IdentityModel.AspNetCore
Due to the way MS has implemented the communication between the UI and back-end, you cannot use traditional cookie-based sessions to store tokens - here's a sample how to work around that:
https://github.com/IdentityModel/IdentityModel.AspNetCore/tree/main/samples/BlazorServer
The store implementation probably needs more work to be "production ready".
Thanks for the follow up, this makes sense for the workaround.
Which version of Duende BFF are you using?
1.2.1
Which version of .NET are you using? 6.0
Describe the bug
Blazor Server Side app, configured with AddBff and AddServerSideSessions, using http client loaded into DI with AddUserAccessTokenHttpClient, open ID connect configured to for a local Duende IDP authority, with offline access and save tokens true.
The client is configured on the IDP with a low access token life time of 120 seconds for testing refresh token behavior.
the HttpClient is used to fetch data from a remote api on the users behalf from blazor server to an aspnet core web api,
after login the user is able to successfully browse to page that calls the api passing its token along with the BFF token management client, after a 60 second period where the token is now eligible for refresh by the BFF token management code, the token is successfully refresh but an exception is throw when it attempts to update the User's session cookie using HttpContext.SignInAsync().
"The response headers cannot be modified because the response has already started."
To Reproduce
configure a blazor server side app with open id connect, bff, serversidesessions (optional happens regardless), AddUserAccessTokenHttpClient, refresh tokens wait for token to expire and let the AddUserAccessTokenHttpClient refresh token and cause the issue.
Expected behavior
AddUserAccessTokenHttpClient is able to update the cookie successfully.
Log output/exception with stacktrace
Additional context
tested in IIS Express and Kestrel, wrote my own delegate handler to mimic the basic implementation of the BFF automatic token management httpclient handler and resulted with the same error.
happy to provide a sample project if needed.
Program.cs of blazor app