Home > Back-end >  ASP.NET Core Identity in a Web API
ASP.NET Core Identity in a Web API

Time:09-04

Are there any guides on how to set up ASP.NET Core Identity for a Web API?

Everything I find uses view models and has the register/login pages displayed on the server as a RazorPage.

MS's Intro document also does this - https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-6.0&tabs=visual-studio

This seems a very old style of set up.

I want my React client to display the register/login forms.

The Web API should just have a registration and login endpoint that returns a DTO. ASP.NET Core Identity being used to store the users in a database in the API, and manage authentication and authorization.

Am I barking up the wrong tree perhaps? Maybe ASP.NET Core Identity just doesn't work this way and I should instead use a hosted user management/authentication solution like AWS Cognito or Auth0?

Thanks

CodePudding user response:

Take a look at this article. It provides the basics of installing packages and configuring them. However to register new users or login users you need to use UserManager and SignInManager classes.

This is the full code of how to implement it with JWT;

  • Related