How to signout from Saml external provider while you are in callback page and the user want to cancel register
Note: the user is not registered yet, he just enter external provider credential and redirect to my IDP to enter the additional data, I want to add action to be able to logout and cancel the registration process.
Logout Code
var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);
if (User?.Identity.IsAuthenticated == true)
{
// delete local authentication cookie
await HttpContext.SignOutAsync();
// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
}
// 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", "Account", new { Area = "Identity", logoutId = vm.LogoutId });
// this triggers a redirect to the external provider for sign-out
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
}
return RedirectToPage("Login");
The answer is just setting the user in the current context so, the saml2 can read the required data to make redirect