PauLy
PauLy

Reputation: 109

How to authenticate a user in a .NET Core MVC frontend, with a .net core identity framework

I have an ASP.NET CORE MVC WebApp with Identity framework. Now that we are also planning to extend our product such that we can provide mobile apps with xamerin, I decided to make an API so that we don't have to code the backend twice. We currently host our App in the Azure Cloud.

For the backend: I would like to use ASP.NET CORE WebApi but I figured that there is no such Identity template nor a native Azure Web API integration. So would it be better to use ASP.NET instead? I already created a basic login AccountController for .net core API.

Since I authenticated the ASP.NET Core MVC Web App via identity framework, I would like to also use that in the backend. So that you log in on the backend and receive a token, once you logged in successfully. I have to code to login the user at the backend and return a token.

How exactly can I authenticate the .NET ASP CORE Frontend? The user will query the login page -> AuthConntroller.Login-> Login method starts a call to Login Backend API -> Backend API queries backend-database -> if successful return true-> backend generates a token->sends it back to frontend-> frontend uses Owin so that I can use the [Authorize] Attribute in the controller classes so that I can authenticate the user?

Anything else that I have to consider when I'm using such an API design?

Thank you so much for any hints/tricks/links/recommendations on my dilemma.

Sincerely, Paul

Upvotes: 0

Views: 2006

Answers (1)

mstfcck
mstfcck

Reputation: 731

If I understand the problem correctly this sources it might be little help:

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio

http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html https://github.com/openiddict/openiddict-core

In such cases, it may not be enough Asp.Net Identity by itself. You can provide Auth server project these libraries for your client projects.

Upvotes: 1

Related Questions