我正在构建使用asp.net 5 rc2 api。我试图执行openiddict-core,发现本地帐户为here,我也希望允许用户使用外部登录名,例如google。没有身份验证处理程序配置为验证该方案:Microsoft.AspNet.Identity.External
我已经设置了这一切,但是当我尝试实施谷歌认证,并且我称这种代码
var info = await _signInManager.GetExternalLoginInfoAsync();
我得到的称号错误消息。
在客户端上,我使用了Satellizer找到的here,它负责打开Google提示窗口并将回调发送到我的AuthController Google方法,这是您在其他mvc6示例中看到的正常ChallengeResult代码。
我已经写代码来获取用户手工细节和工作,但我想我会用已建signInManager代替,而不是再现轮...
我可能没有正确设置好了,因为所有的例子似乎都使用cookies,我猜测这是因为它们是mvc6 web应用程序,而不是api。我不想使用cookies,但这可能是我的问题。
现在有些代码。
startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(_configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddOpenIddict(); // Add the OpenIddict services after registering the Identity services.
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// use jwt bearer authentication
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.RequireHttpsMetadata = false;
options.Audience = "http://localhost:5000/";
options.Authority = "http://localhost:5000/";
});
// Add all the external providers you need before registering OpenIddict:
app.UseGoogleAuthentication(options =>
{
options.AutomaticAuthenticate = true;
//options.AutomaticChallenge = true;
options.ClientId = "XXX";
options.ClientSecret = "XXX";
});
//app.UseFacebookAuthentication();
app.UseOpenIddict();
// Enable all static file middleware
app.UseStaticFiles();
// Enable Mvc for view controller, and
// default all routes to the Home controller
app.UseMvc(options =>
{
options.MapRoute(
name: "default",
template: "{*url}",
defaults: new { controller = "Home", action = "Index" });
});
}
AuthController.cs
ExternalLoginModel.cs
public class ExternalLoginModel
{
public string Code { get; set; }
public string ClientId { get; set; }
public string RedirectUri { get; set; }
}
可能重复[没有认证处理程序配置为处理该方案:自动](https://stackoverflow.com/questions/33825058/no-authentication-handler-is-configured-to-handle-the-scheme-自动) –