public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            // build a model so the logged out page knows what to display
            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", 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));
        }
        private async Task <Response <string> > LogoutServiceAsync(LogoutInputModel viewModel)
        {
            //ÅжÏ
            if (User?.Identity.IsAuthenticated != true)
            {
                return(new Response <string>(success: false, msg: "Óû§Î´µÇ¼,ÎÞÐè×¢Ïú!")
                {
                    Data = "Óû§Î´µÇ¼,ÎÞÐè×¢Ïú!"
                });
            }
            await _signInManager.SignOutAsync();

            //³É¹¦ºóµÄ²Ù×÷
            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));

            return(new Response <string>(msg: "×¢Ïú³É¹¦!")
            {
                Data = $"×¢Ïú³É¹¦!"
            });
        }
Beispiel #3
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

            if (User?.Identity.IsAuthenticated == true)
            {
                await HttpContext.SignOutAsync();

                await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
            }

            if (vm.TriggerExternalSignout)
            {
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });

                return(SignOut(new AuthenticationProperties {
                    RedirectUri = url
                }, vm.ExternalAuthenticationScheme));
            }

            return(View("LoggedOut", vm));
        }
Beispiel #4
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

            if (User?.Identity.IsAuthenticated == true)
            {
                HttpContext.Request.Cookies.Keys.ToList().ForEach(cookie => HttpContext.Response.Cookies.Delete(cookie));

                await HttpContext.SignOutAsync();

                await _eventService.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
            }

            if (!vm.TriggerExternalSignout)
            {
                return(View("LoggedOut", vm));
            }

            var url = Url.Action("Logout", new { logoutId = vm.LogoutId });

            return(SignOut(new AuthenticationProperties {
                RedirectUri = url
            }, vm.ExternalAuthenticationScheme));
        }