2017-04-25 70 views
1

我在.NET的核心谷歌认证工作,但是从谷歌重定向时,它显示我exception- InvalidOperationException异常:无认证处理程序被配置为处理方案:饼干谷歌认证Exception-无认证处理程序被配置为处理方案:饼干

这里是我的startup.cs设置

app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      LoginPath = new PathString("/account/login"), 
      AuthenticationScheme = "MyCookieMiddlewareInstance", 
      AutomaticAuthenticate = true, 
      AutomaticChallenge = true, 
      AccessDeniedPath = new PathString("/Home/AccessDenied"), 
     }); 

     app.UseGoogleAuthentication(new GoogleOptions 
     { 
      AuthenticationScheme = "Google", 
      DisplayName = "Google", 
      SignInScheme = "Cookies", 
      ClientId = "ClientId ", 
      ClientSecret = "ClientSecret ", 
      Scope = { "email", "openid" }, 
      CallbackPath = "/home", 
     }); 

请建议我在哪里,我错了

Error Page

回答

0

您可以通过使用AddCookieAuthentication扩展方法由注册ASP.NET核心提供的默认CookieAuthenticationHandler处理程序:

using Microsoft.AspNetCore.Authentication.Cookies; 

公共无效ConfigureServices(IServiceCollection服务) { services.AddCookieAuthentication(); ... }

更新

有在认证中间件breaking change。现在ASP.NET核心只有一个AddAuthentication()扩展方法和所有配置去扔相应UseXXXAuthentication扩展方法。对于简单的例子看看Security repo samples

using Microsoft.AspNetCore.Authentication.Cookies; 


public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddAuthentication(); 
} 

public void Configure(IApplicationBuilder app) 
{ 
    ... 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AutomaticAuthenticate = true 
    }); 
} 

查找到authentication-cookie部分文档可用选项

+0

AddCookieAuthentication不是IServiceCollection对象的方法。我确认这个名字空间被引用,并且仍然得到这个异常。 –

+0

@NathanTregillus请检查我的更新 – Set