外部IDプロバイダのサインアウト¶
ユーザーがIdentityServer からサインアウトしているときに、外部IDプロバイダを使用してサインインした場合、外部プロバイダからもサインアウトする必要があります。サポートしているプロトコルと機能に依存するため、すべての外部プロバイダがログアウトをサポートするわけではありません。
サインアウトのために外部アイデンティティプロバイダにリダイレクトする必要があることを検出するには、通常idp、IdentityServerのクッキーに発行されたクレームを使用します。このクレームに設定された値AuthenticationSchemeは、対応する認証ミドルウェアの値です。サインアウト時に、この申し立ては外部からのサインアウトが必要かどうかを知るために相談されます。
ユーザーを外部IDプロバイダにリダイレクトすることは、通常のサインアウトワークフローで既に必要とされているクリーンアップと状態管理のために問題があります。IdentityServerで通常のサインアウトとクリーンアッププロセスを完了する唯一の方法は、外部アイデンティティプロバイダから、ログアウト後にユーザーをIdentityServerにリダイレクトするように要求することです。サポートしているプロトコルと機能に依存するため、外部プロバイダはすべてログアウト後リダイレクトをサポートしているわけではありません。
ログアウト時のワークフローでは、IdentityServerの認証Cookieを取り消し、外部プロバイダにリダイレクトしてログアウト後のリダイレクトを要求します。ログアウト後のリダイレクトは、ここで説明する必要なサインアウト状態(つまり、logoutIdパラメータ値)を維持する必要があります。外部プロバイダのログアウト後にIdentityServerにリダイレクトするには、ASP.NET CoreのAPI を使用RedirectUriするAuthenticationProperties場合に使用する必要がありSignOutAsyncます。たとえば、次のようにします。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout(LogoutInputModel model)
{
// build a model so the logged out page knows what to display
var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);
var user = HttpContext.User;
if (user?.Identity.IsAuthenticated == true)
{
// delete local authentication cookie
await HttpContext.SignOutAsync();
// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(user.GetSubjectId(), user.GetName()));
}
// check if we need to trigger sign-out at an upstream identity provider
if (vm.TriggerExternalSignout)
{
// build a return URL so the upstream provider will redirect back
// to us after the user has logged out. this allows us to then
// complete our single sign-out processing.
string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
// this triggers a redirect to the external provider for sign-out
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
}
return View("LoggedOut", vm);
}
ユーザが外部プロバイダからログアウトしてリダイレクトされると、IdentityServerの通常のログアウト処理が実行され、logoutId必要なクリーンアップをすべて処理します。