Asp.net核心2 - WebApi中的外部身份验证

问题描述 投票:5回答:2

现在我知道有很多关于这个的帖子,但我的情况有所不同。所以请耐心等待。

当我在.Net Framework上创建Web Api并选择个人用户帐户时,它已经为我提供了一个用于外部身份验证的工作代码。 qazxsw poi

有AccountController,Startup.auth.cs和其他具有外部认证enter image description here代码的文件

现在我知道.net核心已经发生了变化。但个人用户帐户的net.core web api与它没有任何相似之处。

当我尝试在.net Core上使用WebApi时,它只为我提供了一个选择Azure应用程序的选项。在下图中,使用.net核心上的WebApi,蓝色指向的下拉列表仅提供一个Azure AD b2c应用程序选项。没有帐户控制器是脚手架,也没有其他配置文件用于外部身份验证。

enter image description here

没有我需要的文件。 enter image description here

我试过这些链接:enter image description here

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

但第一个链接是针对.net框架,但对我没有帮助。第二个仅适用于asp.net核心上的Web应用程序,但不适用于WebApi

我需要在web api中进行外部身份验证,因为我希望所有来自Web或移动设备的用户都可以通过Google或Facebook进行身份验证。请任何人指出我正确的方向。我在这里错过了一些东西。有没有文件可以帮我解决这个问题?

authentication .net-core asp.net-core-2.0 asp.net-core-webapi asp.net-authentication
2个回答
0
投票

选择“个人用户帐户”时,您要选择“在应用程序中存储用户帐户”。

以这种方式创建应用程序时,脚手架将创建AccountController。以这种方式创建项目后,您可以转到Startup.cs

在ConfigureServices方法中,您必须添加(对于谷歌):

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

欲了解更多信息,请访问:services.AddAuthentication() .AddGoogle(options => { //Set client Id and secret here options.ClientId = "clientId_here"; options.ClientSecret = "ClientSecret_here"; });


0
投票

您可以使用JSON Web Tokens或JWT。

这是一篇指导正确道路的文章:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/

© www.soinside.com 2019 - 2024. All rights reserved.