Пример #1
0
        public async Task <IActionResult> Logout(IdentityServer4.Quickstart.UI.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 _signInManager.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));
        }
Пример #2
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);

            if (vm.TriggerExternalSignout)
            {
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
                try
                {
                    // hack: try/catch to handle social providers that throw
                    await HttpContext.Authentication.SignOutAsync(vm.ExternalAuthenticationScheme,
                                                                  new AuthenticationProperties { RedirectUri = url });
                }
                catch (NotSupportedException) // this is for the external providers that don't have signout
                {
                }
                catch (InvalidOperationException) // this is for Windows/Negotiate
                {
                }
            }

            // delete local authentication cookie
            await HttpContext.Authentication.SignOutAsync();

            return(View("LoggedOut", vm));
        }
Пример #3
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

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

                await HttpContext.SignOutAsync();

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

            string webURL = _configuration.GetSection("AlgGoURL").Value;

            return(Redirect(webURL));
        }
Пример #4
0
        public async void 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 _signInManager.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

            Response.Redirect(vm.PostLogoutRedirectUri);
        }
Пример #5
0
        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)
            {
                //so that when logged out of the app also grafana auth cookie will be removed hence logging out of grafana.
                RemoveGrafCookie();
                // delete local authentication cookie
                await _signInManager.SignOutAsync();

                // raise the logout event
                await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
            }

            return(View("LoggedOut", vm));
        }
Пример #6
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);

            if (vm.TriggerExternalSignout)
            {
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
                try
                {
                    // hack: try/catch to handle social providers that throw
                    await HttpContext.Authentication.SignOutAsync(vm.ExternalAuthenticationScheme, new Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties {
                        RedirectUri = url
                    });
                }
                catch (NotSupportedException) // this is for the external providers that don't have signout
                {
                }
                catch (InvalidOperationException) // this is for Windows/Negotiate
                {
                }
            }

            var userName = HttpContext.User.Identity.Name;
            // Insert access log
            var accessLog = new ESEIM.Models.AdAccessLog();

            //accessLog.UserId = userName;
            //accessLog.Action = "Logout";
            //accessLog.AccessDate = DateTime.Now;
            //accessLog.IpAddress = HttpContext.Connection?.RemoteIpAddress?.ToString();
            //accessLog.Description = $"{userName} logout";
            //accessLog.AccessLogApplication = "Admin";
            //_context.AdAccessLogs.Add(accessLog);
            //await _context.SaveChangesAsync();
            foreach (var cookie in Request.Cookies.Keys)
            {
                HttpContext.Response.Cookies.Delete(cookie);
            }
            // delete local authentication cookie
            await HttpContext.Authentication.SignOutAsync();

            return(View("LoggedOut", vm));
        }
Пример #7
0
        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)
            {
                var myCookies = Request.Cookies.Keys;

                foreach (string cookie in myCookies)
                {
                    Response.Cookies.Delete(cookie, new CookieOptions()
                    {
                        Domain = "localhost"
                    });
                }

                // 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));
        }
Пример #8
0
        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));
            }
            if (vm.PostLogoutRedirectUri != null)
            {
                return(Redirect(vm.PostLogoutRedirectUri));
            }

            if (string.IsNullOrWhiteSpace(model.LogoutId))
            {
                return(View("LoggedOut", vm));
            }
            var refererUrl = Request.Headers["Referer"].ToString();

            return(Redirect(refererUrl));
        }
Пример #9
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId).ConfigureAwait(false);

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

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

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

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

            return(SignOut(new AuthenticationProperties {
                RedirectUri = url
            }, vm.ExternalAuthenticationScheme));
        }
Пример #10
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);

            if (vm.TriggerExternalSignout)
            {
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
                try
                {
                    // hack: try/catch to handle social providers that throw
                    await HttpContext.Authentication.SignOutAsync(vm.ExternalAuthenticationScheme,
                                                                  new AuthenticationProperties { RedirectUri = url });
                }
                catch (NotSupportedException) // this is for the external providers that don't have signout
                {
                }
                catch (InvalidOperationException) // this is for Windows/Negotiate
                {
                }
            }

            // delete local authentication cookie
            await HttpContext.Authentication.SignOutAsync();

            var user = await HttpContext.GetIdentityServerUserAsync();

            if (user != null)
            {
                await _events.RaiseAsync(new UserLogoutSuccessEvent(user.GetSubjectId(), user.GetName()));
            }

            if (model.ReturnUrl != null)
            {
                return(Redirect(model.ReturnUrl));
            }

            return(View("LoggedOut", vm));
        }
Пример #11
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            //构建模型,以便注销页面知道要显示的内容
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

            if (User?.Identity.IsAuthenticated == true)
            {
                // 删除本地认证cookie
                await HttpContext.SignOutAsync();

                // 提交注销事件
                await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
            }

            // 检查我们是否需要在上游身份提供商处触发注销
            if (vm.TriggerExternalSignout)
            {
                //构建一个返回URL,以便上游提供者重定向回来
                //在用户退出后向我们发送消息。 这让我们接受了
                //完成我们的单点登出处理。
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });

                // 这会触发重定向到外部提供程序以进行注销
                return(SignOut(new AuthenticationProperties {
                    RedirectUri = url
                }, vm.ExternalAuthenticationScheme));
            }
            //正常退出直接重定向 不使用系统退出流程
            if (!string.IsNullOrEmpty(vm.PostLogoutRedirectUri))
            {
                return(Redirect(vm.PostLogoutRedirectUri));
            }
            else
            {
                return(Redirect("/home/index"));
            }
            // return View("LoggedOut", vm);
        }