使用UseGoogleAuthentication

时间:2016-07-04 21:30:05

标签: .net asp.net-core google-oauth .net-core

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

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

dotnet new --type web

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

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

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

但是,按照这里的教程,以下行应该返回一个带有一个元素的loginProvider集合:

SignInManager.GetExternalAuthenticationSchemes()

但我得到的只是一个空的IEnumerable。我试图遵循源代码,但未能找到我做错了什么(错误的客户端ID配置,错过了启动配置(服务)功能中的内容)。

如何让SignInManager.GetExternalAuthenticationSchemes()返回google loginProvider?

1 个答案:

答案 0 :(得分:3)

经过一些测试,我发现了它。我的错误是在UseGoogleAuthentication之后使用UseMvc。在修复我的问题之前移动它。

我想这篇文章解释了它:

Developer Exception Page is blank if added to IApplicationBuilder after MVC

相关问题