verwende ich Cookie-Authentifizierung mit Google mit folgenden Optionen:ASP.NET-Core Web Application ExpireTimeSpan in UseCookieAuthentication funktioniert nicht
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "MyCookieMiddlewareInstance",
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ExpireTimeSpan = TimeSpan.FromDays(14.0)
});
app.UseGoogleAuthentication(new GoogleOptions()
{
SignInScheme = "MyCookieMiddlewareInstance",
AutomaticAuthenticate = true,
ClientId = "xxx",
ClientSecret = "xxx"
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
[HttpGet]
[AllowAnonymous]
public IActionResult ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
return RedirectToLocal(returnUrl);
}
Nach der Autorisierung über Google Cookies nach 30 Minuten abgelaufen sein. Und sie sind für die Sitzung erstellt.
Was soll ich tun exparation Zeit zu erhöhen?
Vielen Dank für Ihre Antwort! Ich habe app.UseIdentity(); to Startup.cs, aber jetzt warten _signInManager.GetExternalLoginInfoAsync(); ist immer null und es leitet mich auf die Anmeldeseite um, wenn ich in der App autorisiert habe. Ich habe versucht, dieses Problem zu suchen, aber ich habe keine Lösung gefunden. –
Ich löse dieses Problem, um app.UseCookieAuthentication in Startup.cs zu kommentieren Jetzt habe ich die Ausnahme in erwarten _signInManager.ExternalLoginSignInAsync "Kein Datenbank-Provider wurde für diesen DbContext konfiguriert". Ich habe services.AddDbContext(); und. AddEntityFrameworkStores (); in Startup und kann sie nicht loswerden, weil die Anwendung ohne sie nicht funktioniert. –
Am Ende habe ich app.UseIdentity() entfernt; von StartUp und hinzugefügt erwarten HttpContext.Authentication.SignInAsync ("MyCookieMiddlewareInstance", Benutzer, Eigenschaften); zu ExternalLoginCallback wie folgt: [http://i.imgur.com/fpLiiGS.png](http://i.imgur.com/fpLiiGS.png] Es funktioniert für mich. –