10

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://learn.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

2 Answers 2

11

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;

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much. This is more like it! I still feel like I'm building my own Auth solution using Identity Core though. Or copying someone's half-baked attempt from github. Which is what everyone says don't do. I'm not sure it's really fit for purpose anymore. Maybe Azure B2C or AWS Cognito or Google Firebase is where it's at nowadays.
6

If you can update your project to asp.net core 8 best solution will be using Identity API endpoints. This is identity end point example. If you still want to keep you own implementation in top of asp.net core identity this example have complete extendable code with react.

2 Comments

Are these .net 8 endpoints configurable? It comes with a lot of enabled endpoints out of the box which I might not need all of them. Is there a way to disable any of them?
Unfortunately ,You can't change which endpoints are added, this is the one disadvantage . you can read more here andrewlock.net/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.