Skip to content

ASP.NET Core SPA Templates Need Better Options for Authentication #42158

Closed

Description

@Grauenwolf

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to create basic SPA applications that manage their own passwords without the cost and complexity of third-party products like Identity Server.

Other's I'm talking to just want simple social media authentication.

We're all at a loss as to how to achieve this because none of the SPA templates give us any direction on how to proceed. There are out-of-band tutorials we can look at. But they are often incomplete or confusing, which is not acceptable for something that has to be perfect on day one. The phrase, "I'm learning authentication by trial-and-error" is quite frightening.

Describe the solution you'd like

The SPA templates for Angular, React, Blazor, etc. should include options for...

  • ASP.NET Identity for cookie-based authentication (i.e. not Identity Server)
  • Microsoft Identity
  • Azure B2C
  • Azure Active Directory
  • Generic OAuth with JWT template
  • any other Microsoft-supported authentication platform

Additional context

We are regularly seeing posts on Reddit with titles like "Why is authentication such a XXXX show with .NET 6?" and "Does anyone else feel as lost as I do in the .NET Identity documentation?". The community is having a really hard time with this and needs far better guidance than what we're getting.

Activity

  1. MJomaa commented on Jun 12, 2022

    @MJomaa

    + 1

    I don't even know why you would need identity server when starting out with a web project. It's overkill and requires licensing.

    WebApp with internal API

    I wish there was a SPA template with session cookie authentication, CSRF protection, Microsoft+Google federated login and scaffolded UI where you change everything, even the routes.

    Public API

    If you want to offer a public API it's trivial to implement client credentials flow where the client credentials can be generated in the web app (usually under "organization" or "account settings")

  2. toddbauermeister commented on Jun 12, 2022

    @toddbauermeister

    +1

    My recent experience with Blazor Server and scaffolding in Auth pages for customisation (which are .cshtml and not .razor pages) was not super fun or intuitive tbh 😅

    It would have been really nice to have a template with a choice of provider(s) / auth components to be included in the template by default, and the support to scaffold in .razor pages (or even include some of the most important ones in the project by default) many people including myself have been confused that there is a project with pages which 'don't exist' in the solution until you scaffold them in.

  3. DavidKrowitz commented on Jun 12, 2022

    @DavidKrowitz

    Pretty please with a bow on top!

    Would make the lives of working professional coders a lot easier.

  4. GuerrillaCoder commented on Jun 12, 2022

    @GuerrillaCoder

    Also an example using openiddict which is free instead of identity server that would require a license for us to use.

  5. atresnjo commented on Jun 12, 2022

    @atresnjo

    Also an example using openiddict which is free instead of identity server that would require a license for us to use.

    https://github.com/openiddict/openiddict-samples/tree/dev/samples/Hollastin/Hollastin.Server

  6. dajma00 commented on Jun 13, 2022

    @dajma00

    Even trying to do an API with auth, we are at a loss. A Laravel team tried and failed. Went back to Laravel.

  7. robheffo79 commented on Jun 13, 2022

    @robheffo79

    Honestly, Authentication is terrible. It's overcomplicated and slow.

    I implemented my own Authentication platform that completely hides the default built-in system, It's much faster than the stock system. I would share it but it's for a client and I don't own the rights to the code

    Authentication needs to be split out into its own libraries and not as part of the core of ASP.NET 6.

  8. MJSanfelippo commented on Jun 13, 2022

    @MJSanfelippo

    That would be fantastic.

  9. taylorchasewhite commented on Jun 13, 2022

    @taylorchasewhite

    Here are related issues I wrote (focused on the documentation, but certainly reflect the same concerns):

    1. Understanding & Using Microsoft Identity (StackOverflow)
    2. Blazor WASM Additional Authentication Scenarios (#221222)
    3. AzureAD Blazor Issues #19803
    4. AzureAD Blazor Claims Issues #19576
    5. BaseAddressAuthorizationMessageHandler #18344

    FWIW, we largely did our own work as well to make auth work in our Blazor WASM app and divorce from Identity Server, but I would much rather use a well supported foundation than what I built.

    Thanks @Grauenwolf for your suggestions.

  10. prince272 commented on Jun 13, 2022

    @prince272

    I'm happy that these are now concerns to the community. When standalone react and api application was introduced, I thought authentication would be improved upon but I rather saw complexity of third-party products like Identity Server, etc. I'm currently considering identify server 4 with OID client and still stuck with Net 5.
    But I'm hoping there would be a better solution like what @MJomaa suggested. Thank you

  11. kyledevans commented on Jun 14, 2022

    @kyledevans

    I've managed to implement both username/password and the Microsoft Identity Web platform into a react SPA + backend API project. But it's been a hugely complicated task, and while it's great when I look back at how much I've learned, I doubt anyone wants to spend 6+ months digging into the deepest depths of ASP in order to come up with a production-ready implementation. The only reason I was able to do it is because Covid forced me to take a lot of time off work.

    If it's at all helpful, I have a working implementation here: Kiddo (Username/Password/Azure Ad web app). It uses JWTs instead of cookies, but on the server side it still uses the ASP Identity framework for managing usernames/passwords.

    I fully get that adding even a stripped down version of what I've managed to get working is a bit much for a template. There's simply so much boilerplate necessary simply to get the server-side API to work. That's not considering all of the UI components and integration with your site branding and design.

    I've wondered at the possibility that we (the community and ASP teams) could come up with a REST protocol to at least streamline the server-side component. From there it would be up to individual teams to write the actual SPA frontend that integrates with the API.

  12. chindilhan commented on Jun 15, 2022

    @chindilhan

    Yes this is a must have, easy to use feature. We've switched few projects to other techs just because of this auth nightmare.

  13. robert-txt commented on Jun 15, 2022

    @robert-txt
  14. 160 remaining items

  15. luanmm commented on Nov 23, 2023

    @luanmm

    You have the option to install an older version, then keep a copy of the template's structure in a project of yourself to serve as base for new projects, if the old structure matter this much to you.

    My point is: what you propose, to the limit, would've made Visual Studio 2022 had templates from the very first version only "because someone wants", without considering improvements made to the stack, using feedback of hundreds of people.

    I was a stubborn person in the past too and maybe even had thoughts similar to yours (because we, humans, don't handle well with changes), but the new product versions have a purpose behind the changes. For instance, if .NET 8 have a new type of project specific for the web, considering the new stack technologies, there is a point to start using it instead of the older MSBuild template (because of a better ecosystem, debugging, maturity, security, etc).

    What I see about some changes is that Visual Studio older templates are very opinionated on its structure, because of the way the stack was seen with proprietary technologies in Microsoft. This is not true for all stacks, because, in general, web stacks are "shared" between a lot of other stacks (PHP, Python, Ruby, etc), and seems (to me) that making things more independent would help even new developers to access the .NET ecosystem. I have no deeply knowledge of why the new structure exists, but I can see this movement between older and new structures, which makes sense to me at least.

    You always have the possibility to stick with older versions until you can manage to update or until the new stack has the maturity needed. This is indeed a possibility, because not every improvement (in the history of .NET) had come with 100% of the features the last version was (this is something that happens not so unfrequently, like in the transition between .NET Framework to .NET Core, EF -> EF Core, and so on...).

    It is great that you can give your opinion to improve the technology, and I hope it helps the team to fill any gaps that this new type of web project have. Until it happens, the best discussion I see is to discover what exactly are the problems/gaps in the new version that aren't fulfilled by the new templates. Concrete examples would be more helpful than saying that "you and other developers want it".

    References that may help you:

    Some personal guidance that may help you (or someone else) to "migrate": old SPA templates had API and static code tightly coupled, which is something that is not so trivial in SPA projects - where the most common scenario (that I see) is that you would have an API (written as a WebAPI project in .NET, for instance) and a separate project for the static part of your client's code (Angular, React, Vue, etc), which would be your SPA project in fact. Then, you keep things separated, mainly because you could serve the static code in an edge server, for instance, and your API/BFF as a dynamic application, in any server. This way you have independent scalability, maintainability, etc... so it is a more logical way of thinking the project responsabilities. And maybe this is something that was considered in this movement between .NET 7 and .NET 8 (just a guess, as I already stated).

    Anyway... hope you find a better way to work (perhaps without needing to stick with the old stack).

    Best regards.

  16. joonatenhunen commented on Nov 23, 2023

    @joonatenhunen

    You have the option to install an older version, then keep a copy of the template's structure in a project of yourself to serve as base for new projects, if the old structure matter this much to you.

    My point is: what you propose, to the limit, would've made Visual Studio 2022 had templates from the very first version only "because someone wants", without considering improvements made to the stack, using feedback of hundreds of people.

    I was a stubborn person in the past too and maybe even had thoughts similar to yours (because we, humans, don't handle well with changes), but the new product versions have a purpose behind the changes. For instance, if .NET 8 have a new type of project specific for the web, considering the new stack technologies, there is a point to start using it instead of the older MSBuild template (because of a better ecosystem, debugging, maturity, security, etc).

    If you install latest .net SDK and latest Visual Studio 2022 updates you must be able to use SPA Template projects for .net 6, 7, 8 -> But now it is not possible and promised updated version of SPA Templates without "Duende IdentityServer" dependency for .net 8 is not there available to use with any .net 6-8 versions (single project SPA template what will suits the best for our needs). https://devblogs.microsoft.com/dotnet/improvements-auth-identity-aspnetcore-8/

    You cannot install side by side multiple Visual Studio 2022 instances but that is not at all relevant case.

  17. luanmm commented on Nov 23, 2023

    @luanmm

    So the thing is that the new SPA templates are missing (not the old ones), right?

    As I see in docs, the new SPA templates should be available right in Visual Studio 2022, like stated here.

  18. joonatenhunen commented on Nov 24, 2023

    @joonatenhunen

    So the thing is that the new SPA templates are missing (not the old ones), right?

    As I see in docs, the new SPA templates should be available right in Visual Studio 2022, like stated here.

    I mean SPA templates what was promised to improve to .net 8 where "Duende IdentityServer" dependency is removed and still it is single project template ( https://devblogs.microsoft.com/dotnet/improvements-auth-identity-aspnetcore-8/ ). Should be possible to start a new project using that updated SPA project template using .net 6 to 8 versions where "Duende IdentityServer" is not there with cookie auth etc..

    Following git commits are not part of latest SDK

    e849963

    #48431

  19. kjartanvalur commented on Nov 26, 2023

    @kjartanvalur

    @JeremyLikness @damienbod @davidfowl
    I would really like to see a tutorial on two factor authentication for SPA´s using the new Identity Api Endpoints.

  20. tusmester commented on Nov 26, 2023

    @tusmester

    I know this might be offtopic in this issue but still, I would be grateful if you could give me guidance about where I should look for advice.

    My use case: I have a web app representing a repository (resources to secure and stores user data) and a separate token auth server, using IdentityServer 4 (the previous, opensource version of Duende). This setup supports OAuth2 (and OIDC). My question is: if I wanted to do the same, which template should I use in .Net 8 and how would I implement this without having to license Duende?

    It would be nice to have a similarly easy-to-use, open-source solution for an OAuth2 auth server as before. Not sure if the new identity API in .Net 8 would help me as that is not a JWT-compatible solution. I would like to have an auth server that supports SSO (single-sign-on) whithout having to deal with OAuth2 implementation, I only want to customize the user store and the login UI. This is what IdentityServer let me do before, out of the box. I know of OpenIdDict but that is a lot more complicated than IS4 was.

  21. davidfowl commented on Nov 26, 2023

    @davidfowl
    Member

    It would be nice to have a similarly easy-to-use, open-source solution for an OAuth2 auth server as before. Not sure if the new identity API in .Net 8 would help me as that is not a JWT-compatible solution. I would like to have an auth server that supports SSO (single-sign-on) whithout having to deal with OAuth2 implementation, I only want to customize the user store and the login UI. This is what IdentityServer let me do before, out of the box. I know of OpenIdDict but that is a lot more complicated than IS4 was.

    I found this post pretty insightful https://www.reddit.com/r/dotnet/comments/17qnvyv/choosing_an_identity_provider_authentication/

    There's no, out-of-the-box template for an OIDC server outside of Entra, but each of those providers has docs on how to get started with ASP.NET Core.

  22. MoishyS commented on Nov 27, 2023

    @MoishyS

    My use case: I have a web app representing a repository (resources to secure and stores user data) and a separate token auth server, using IdentityServer 4 (the previous, opensource version of Duende). This setup supports OAuth2 (and OIDC). My question is: if I wanted to do the same, which template should I use in .Net 8 and how would I implement this without having to license Duende?

    I'll just mention, if you only have one web app, I don't see any reason to have a separate OIDC auth server

  23. tusmester commented on Nov 27, 2023

    @tusmester

    I'll just mention, if you only have one web app, I don't see any reason to have a separate OIDC auth server

    Thank you, that is absolutely true. However in our case the goal is to support multiple clients, including other asp.net apps, spas, even mobile apps - with single sign on.

  24. ghost closed this as completedon Jan 26, 2024
  25. taylorchasewhite commented on Jan 26, 2024

    @taylorchasewhite

    Well…I’m not sure exactly the scope of this issue anymore after the hundreds of comments(!), but I assume it should be closed by a human or broken into smaller issue instead of as stale by you @msftbot!

  26. JeremyLikness commented on Jan 26, 2024

    @JeremyLikness
    Member

    Hi, we're looking at this and will clarify what issues/PRs are related and update accordingly.

  27. zkdiff commented on Apr 3, 2024

    @zkdiff

    @JeremyLikness Any chance that there have been some new issues or PRs related to this in the last few months? I'm very interested in this topic and would like to follow up on any further advancements. Thank you!

  28. locked and limited conversation to collaborators on May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authIncludes: authentication, authorization, OAuth, OIDC, and access token validationfeature-spa

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions