Asp.net CoreIdentityバージョン2.0をセットアップして実行しています。私はそれを見つけています_signinManager.SignoutAsync
ユーザーがGoogleにログインすると、ユーザーはログアウトしません。ログインメソッドに戻ると、Claimsオブジェクトがそのままの状態でログインしているユーザーが表示されます。
コードは以下のように本当にシンプルです
[AllowAnonymous]
public ActionResult TestGoogle()
{
var redirectUrl = Url.Action(nameof(ExternalCallback), "Account", new { ReturnUrl = "" });
var properties = _signInManager.ConfigureExternalAuthenticationProperties("Google", redirectUrl);
return Challenge(properties, "Google");
}
public async Task<IActionResult> LogOff()
{
await _signInManager.SignOutAsync();
return RedirectToAction(nameof(HomeController.Index), "Home");
}
問題は、RedirectToAction
がSignOutAsync
が発行するIdentityServerエンドセッションURLへのリダイレクトを上書きすることです。
SignOutAsync
に関しては、廃止されたのはAuthentication
部分です。ASP.NETCore2.0の時点では、HttpContext
自体から直接拡張されています。
(同じサインアウトの問題について同じ説明が与えられています ここ MicrosoftのHaoKによって。)
編集:解決策は、リダイレクトURLをAuthenticationProperties
オブジェクトで最後のSignOutAsync
とともに送信することです。
// in some controller/handler, notice the "bare" Task return value
public async Task LogoutAction()
{
// SomeOtherPage is where we redirect to after signout
await MyCustomSignOut("/SomeOtherPage");
}
// probably in some utility service
public async Task MyCustomSignOut(string redirectUri)
{
// inject the HttpContextAccessor to get "context"
await context.SignOutAsync("Cookies");
var prop = new AuthenticationProperties()
{
RedirectUri = redirectUri
};
// after signout this will redirect to your provided target
await context.SignOutAsync("oidc", prop);
}
最初の行だけで私の問題は解決しました。
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await _SignInManager.SignOutAsync();
HttpContext.Response.Cookies.Delete(".AspNetCore.Cookies");