public async Task EndSession() { if (User.Identity.IsAuthenticated) { IAzureAdTokenService tokenCache = (IAzureAdTokenService)HttpContext.RequestServices.GetService(typeof(IAzureAdTokenService)); tokenCache.Clear(); } // If AAD sends a single sign-out message to the app, end the user's session, but don't redirect to AAD for sign out. await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); }
// Clear the cache of tokens for the user, and send a sign out request to AAD public async Task SignOut() { if (User.Identity.IsAuthenticated) { IAzureAdTokenService tokenCache = (IAzureAdTokenService)HttpContext.RequestServices.GetService(typeof(IAzureAdTokenService)); tokenCache.Clear(); await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme); } }