没有配置身份validation处理程序来validation该方案:Microsoft.AspNet.Identity.External

我正在使用asp.net 5 rc2构建一个api。 我正在尝试实现openiddict-core,在这里找到本地帐户,我也想让用户使用外部登录,例如谷歌。

我已经设置了所有,但当我尝试实现谷歌身份validation,我称之为代码

var info = await _signInManager.GetExternalLoginInfoAsync();

我在标题中收到错误消息。

在客户端我正在使用这里找到的Satellizer,它负责打开google提示窗口并将回调发送到我的AuthController Google方法,这是您在其他mvc6示例中看到的正常ChallengeResult代码。

我已经编写了代码来手动获取用户的详细信息,但是我认为我会使用已经构建的signInManager,而不是重现轮…

我可能没有正确设置,因为所有示例似乎都使用cookie,我猜测是因为它们是mvc6 Web应用程序,而不是api。 我不想使用cookies,但这可能是我的问题。

现在为一些代码。

startup.cs

 public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container. services.AddMvc(); services.AddEntityFramework() .AddSqlServer() .AddDbContext(options => options.UseSqlServer(_configuration["Data:DefaultConnection:ConnectionString"])); services.AddIdentity() .AddEntityFrameworkStores() .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

 public class AuthController : Controller { private UserManager _userManager; private SignInManager _signInManager; private ApplicationDbContext _applicationDbContext; public AuthController( UserManager userManager, SignInManager signInManager, ApplicationDbContext applicationDbContext) { _userManager = userManager; _signInManager = signInManager; _applicationDbContext = applicationDbContext; } [HttpPost("google")] public async Task GoogleAsync([FromBody] ExternalLoginModel model) { // THIS IS WHERE ERROR OCCURS var info = await _signInManager.GetExternalLoginInfoAsync(); return Ok(); } } 

ExternalLoginModel.cs

 public class ExternalLoginModel { public string Code { get; set; } public string ClientId { get; set; } public string RedirectUri { get; set; } } 

您是否尝试通过添加app.UseIdentity();注册Identity中间件app.UseIdentity(); 在注册GoogleAuthentication中间件之前?