Kernel Asp.net 2 - External authentication in WebApi

Now I know that there are many reports of this, but my case is different. So please bear with me

When I create WebApi on the .Net Framework and select individual user accounts, it already substitutes the working code for external authentication. enter image description here

There is AccountController, Startup.auth.cs and other code files for external authentication enter image description here

Now I know that things have changed for the .net kernel. But net.core web api in individual user accounts does not resemble anything.

When I try to do the same with WebApi on .net Core, it provides me with only one option to select any Azure application. In the figure below, with the WebApi on.net database, this drop-down list, indicated in blue, provides only one option, which is the Azure AD b2c application. There is no user account controller or other configuration files for external authentication.

enter image description here

There are no files that I need. enter image description here

I tried these links: https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/external-authentication-services

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/

But the first link is for the .NET Framework, which does not help me. The second only works for an asp.net core web application, but NOT WebApi

I need external authentication in the web api because I want all my users from the Internet or mobile device to be authenticated by Google or facebook. Anyone please point me in the right direction. I missed something. Are there any documents that can help me?

+5
source share
2 answers

When you select "Individual user accounts," you want to select "Save user accounts in the application."

When you create an application this way, scaffolding will create an AccountController. Once you have created your project this way, you can go to Startup.cs

In the ConfigureServices method you should add (for google):

services.AddAuthentication() .AddGoogle(options => { //Set client Id and secret here options.ClientId = "clientId_here"; options.ClientSecret = "ClientSecret_here"; }); 

For more information: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/

0
source

You can use JSON Web Tokens or JWT.

Here is an article to help you find the right path: https://auth0.com/blog/securing-asp-dot-net-core-2-applications-with-jwts/

0
source

Source: https://habr.com/ru/post/1274549/


All Articles