Ich baue eine API mit asp.net 5 RC2. Ich versuche, openiddict-core, gefunden here für lokale Konten zu implementieren, und ich möchte auch zulassen, dass Benutzer externe Logins wie Google verwenden.Kein Authentifizierungshandler ist für die Authentifizierung für das Schema konfiguriert: Microsoft.AspNet.Identity.External
Ich habe alles eingerichtet, aber wenn ich versuche, die Google-Authentifizierung zu implementieren, und ich nenne diesen Code
var info = await _signInManager.GetExternalLoginInfoAsync();
erhalte ich die Fehlermeldung im Titel.
Auf dem Client bin ich mit Satellizer gefunden here, die kümmert sich um das Öffnen der Google Eingabeaufforderungsfenster und senden Sie den Rückruf an meine AuthController Google-Methode, die den normalen ChallengeResult-Code in anderen MVC6 Beispiele sehen.
I-Code haben, schrieb die Benutzer erhalten Details manuell und das funktioniert, aber ich dachte, ich die bereits gebaut signInManager stattdessen verwenden würde, anstatt das Rad reproduzieren ...
ich die Dinge gesetzt werden korrekt nicht auf , da alle Beispiele anscheinend Cookies verwenden, was vermutlich darauf zurückzuführen ist, dass es sich um mvc6-Webanwendungen handelt, nicht um eine API. Ich möchte keine Cookies verwenden, aber das könnte mein Problem sein.
Jetzt für etwas Code.
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
public class AuthController : Controller
{
private UserManager<ApplicationUser> _userManager;
private SignInManager<ApplicationUser> _signInManager;
private ApplicationDbContext _applicationDbContext;
public AuthController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
ApplicationDbContext applicationDbContext)
{
_userManager = userManager;
_signInManager = signInManager;
_applicationDbContext = applicationDbContext;
}
[HttpPost("google")]
public async Task<IActionResult> 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; }
}
Mögliches Duplikat von [Kein Authentifizierungshandler ist für die Behandlung des Schemas konfiguriert: Automatisch] (https://stackoverflow.com/questions/33825058/no-authentication-handler-is-configured-to-handle-the-scheme- automatisch) –