使用 UseGoogleAuthentication

using UseGoogleAuthentication

我正在尝试构建一个应用程序 google 作为 asp.net 核心中的身份提供者。

我使用了由 dotnet cli 工具初始化的 bootstrap Web 应用程序:

dotnet new --type web

我在 project.json 中添加了 Microsoft.AspNetCore.Authentication.Google nuget。

我创建了一个 google 应用程序和一个 clientid/secret 并添加了 google 中间件:

app.UseGoogleAuthentication(new GoogleOptions{
                ClientId = "<clientId>",
                ClientSecret = "<clientSecret>"
            });

但是,按照此处的教程,下一行应该 return 一个包含一个元素的 loginProvider 集合:

SignInManager.GetExternalAuthenticationSchemes()

但我得到的只是一个空的 IEnumerable。我试图按照源代码进行操作,但未能找到我做错了什么(客户端 ID 配置错误,启动配置(服务)函数中遗漏了一些内容)。

如何让 SignInManager.GetExternalAuthenticationSchemes() 到 return google loginProvider?

经过一些测试,我明白了。我的错误是在 UseMvc 之后使用 UseGoogleAuthentication。将其移动到解决我的问题之前。

我想这个帖子解释了它: