gpt4 book ai didi

authentication - Asp.net core 2 - Web Api 中的外部身份验证

转载 作者:行者123 更新时间:2023-12-03 17:36:01 26 4
gpt4 key购买 nike

现在我知道已经有很多关于这个的帖子了,但我的情况不同。所以请多多包涵。

当我在 .Net Framework 上创建 WebApi 并选择个人用户帐户时,它已经为我搭建了一个用于外部身份验证的工作代码。
enter image description here

有 AccountController、Startup.auth.cs 和其他具有外部身份验证代码的文件
enter image description here

现在我知道 .net 核心的情况发生了变化。但是个人用户帐户上的 net.core web api 没有提供类似的东西。

当我尝试对 .net Core 上的 WebApi 执行相同操作时,它只为我提供了一个选项来选择一些 Azure 应用程序。
在下图中,使用 .net 核心上的 WebApi,蓝色指向的下拉菜单仅提供一个选项,即 Azure AD b2c 应用程序。没有帐户 Controller 被搭建,也没有其他用于外部身份验证的配置文件。

enter image description here

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

我试过这些链接:
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/

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

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

最佳答案

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

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

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

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

欲了解更多信息,请查看: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/

关于authentication - Asp.net core 2 - Web Api 中的外部身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48134305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com