-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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 App, individual Accounts and Authorization #52800
Comments
I was trying a similar scenario: Blazor App (SSR) With Identity UI -> API (Identity) Other than start modifying Login.razor, Register.razor and problably a few other razor components to talk to the Identity endpoints in the API project, I don't know what else could/should be done. Would love some advice, or ideally a good sample on the right way to proceed. |
@famda @julioct First, what you want to implement is more suitable for WASM Standalone, because I believe one of the main advantages of Blazor is you don't need to write API. For server mode and SSR you can get access to all stuff of the server without sending API. What I understand:If you want to implement identity logic through API project, you must do things like WASM. You can check the sample. The most important part is how to implement the For default template, the authentication state is auto assigned internally. I believe it's because the But if you place your identity logic in API Project, the This creates complex and breaks the advantage of Blazor. It's just like a JS/WASM Frontend + .NET Backend. |
Hi, The idea of having the DbContext (even on the "Host" project) is not the expected. What I'm trying to achieve is to have the same setup but using the new identity endpoints, flow the claims of the user to the client and using the necessary AuthenticationStateProvider. |
I just have a quick look of the |
I do think there is difficulty for auto mode. For standalone WASM, HttpClient is used as Browser Fetch, you can get/set cookie to get user info from API. But when the render mode is Server, you need to add cookie/token into HttpClient Request payload. |
The repo has a dotnet8 branch and it's actually well designed and it's not that complex. The only missing part are the actual claims flowing and the correct AuthenticationStateProviders and PersistentComponentState both on server and the client. Maybe, @halter73 or @SteveSandersonMS can also provide some guidance on properly design this. 😀 |
The ASP.NET Core Identity system is designed to authenticate a single web application. You could theoretically give the same app name and data protection keys to your blazor frontend and API backend, and then they could decrypt the same cookie/token and read the claims, but we recommend using either a cloud or self-hosted OIDC service for BFF. Take a look at https://learn.microsoft.com/en-us/aspnet/core/security/how-to-choose-identity-solution?view=aspnetcore-8.0#identity-vs-oidc-server to see what our recommendations are in this area. If you do want to use and OIDC server to do BFF, take a look at the Blazor OIDC BFF sample I've been working on at dotnet/blazor-samples#137. We hope to get a full article using that sample published soon, but I can answer questions about it in the meantime. If you want just to authenticate a Blazor WASM app with And if you're using the new Blazor template with auto interactivity, I recommend just using the "Individual Auth" template. This doesn't do BFF, but that isn't a supported scenario for ASP.NET Core Identity. |
@halter73 Thanks a lot for all these great Identity improvements in ASP.NET Core 8. Do you have any comments on https://github.com/davidfowl/TodoApi? I have a PR here to get it all updated to .NET 8 RTM goodness: davidfowl/TodoApp#90 It uses the latest Blazor bits and the new identity endpoints, so I'm hoping to use it as a reference sample. |
Bit late to the party but have a look at my project PortalForgeX Blazor 8 - AutoRenderMode, so its mixed.
|
You should look at Damien Bods website and github Repo, as he has a lot to say about this topic and is a contributor to asp.net. He creates a lot of projects using BFF in different configurations |
Closing as it seems no further action is pending here from the team. |
Hi,
I'm trying to implement a BFF with the new features of Identity (dotnet 8) using the new template Blazor App (using Auto Interactive render modes).
The current template (when including the respective auth option), creates everything and uses ef core on the "host" project. However, the idea was to use the identity endpoints on a separate api project (BFF).
API (identity) <- Blazor App (server) <- Blazor (client)
Another issue that I've found is to flow claims (roles, custom claims) to the client (does it require to have a custom endpoint on the api to serve this data? - the cookie/token have all that data in it).
(There is an issue opened with a PR on the blazor-samples repo but the proposed PR for standalone wasm w/ identity seems a hack).
The current documentation doesn't help with the available samples/information.
Can you please provide guidance/sample for this, please?
The text was updated successfully, but these errors were encountered: