Search code examples
angularasp.net-web-apiidentityserver4

Register, Login, Confirm Email and Password Reset In Angular 6 / ASP.Net Core


We are building more and more web applications using the Angular template included with the latest version of Visual Studio 2017 (currently preview 4).

So, on my current development machine, I have .Net Core 2.1.400-preview-009171 and Angular CLI 6.0.8.

I start with the Angular template bundled with Visual Studio 2017 Preview 4. I then go in to the package.json file and upgrade all of the references to the current versions.

All that said, here is my issue. Almost every app I have in the works has requirements for the following:

  1. User registration
  2. Email confirmation
  3. Password reset capability

Everything I have been able to find as a guide for my scenario thus far involves using MVC for the Register, Login and Password reset forms. So you have to route from the SPA to MVC and back for the authentication stuff. Then you use refresh tokens between the SPA and the API. Is there an approach that allows you to use Identity/IdentityServer4 for the authentication while not having to use MVC Views, etc?

First time posting here... hope I don't get shamed too bad.


Solution

  • I think you need to ask yourself some questions. Do you need Identity Server? The principle of an OAuth Provider is that you redirect users to the 'Authorization server' and handle stuff there. The use case here is SSO and not having the need to build authentication for every app you write.

    But as you don't want the MVC views I have a feeling you are not really needing Identity Server. (You can always port the whole Identity Server app to Angular / React / Vue but I don't see the point in doing that, Authenication is mostly not the core business of a company)

    There is however a flow where you don't need the MVC views. The resource owner password credentials flow. Than you can send password and username trough your backend API to your Identity Server and you will receive an access token and you can also enable refresh tokens. There are tutorials for this on the web.

    But if you are really going to only use Identity Server for this use case. I would just do it yourself.

    Create an API that uses Identity (with some basic routes /login /register ...) and generate your access tokens yourself. There are plenty of examples to do that in ASP.Net Core on the web.

    I hope I could help you a bit.