Пример #1
0
        public async Task <LoggedOutOutput> ExecuteAsync(string logoutId)
        {
            var getLogoutRequestTask = _logoutService.GetLogoutRequestAsync(logoutId);
            var claimsPrincipal      = _claimsPrincipalService.GetClaimsPrincipal();
            var logoutRequest        = await getLogoutRequestTask;

            if (claimsPrincipal?.Identity != null && claimsPrincipal.Identity.IsAuthenticated)
            {
                var signOutTask = _signOutService.SignOutAsync();

                if (logoutRequest.SubjectId.HasValue)
                {
                    await _persistedGrantRepository.DeleteAllBySubjectIdAsync(logoutRequest.SubjectId.Value);
                }

                var   idp = _claimsPrincipalService.GetNonLocalIdentityProvider(claimsPrincipal);
                await signOutTask;

                if (!string.IsNullOrWhiteSpace(idp) && await _schemeService.SchemeSupportsSignOutAsync(idp))
                {
                    if (string.IsNullOrWhiteSpace(logoutId))
                    {
                        logoutId = await _logoutService.CreateLogoutContextAsync();
                    }

                    return(new LoggedOutOutput(logoutId, logoutRequest.PostLogoutRedirectUri,
                                               logoutRequest.SignOutIFrameUrl, logoutRequest.ClientId, idp));
                }
            }

            return(new LoggedOutOutput(logoutId, logoutRequest?.PostLogoutRedirectUri,
                                       logoutRequest?.SignOutIFrameUrl, logoutRequest?.ClientId, null));
        }
Пример #2
0
        public async Task <IActionResult> Logout(string logoutId)
        {
            LogoutRequest logoutRequest = await logoutService.GetLogoutRequestAsync(logoutId);

            await logoutService.SignOutAsync(logoutRequest);

            var redirectUrl = logoutRequest?.PostLogoutRedirectUri;

            if (string.IsNullOrWhiteSpace(redirectUrl))
            {
                redirectUrl = publicBrowseSettings.LogoutAddress.ToString();
            }

            return(Redirect(redirectUrl));
        }
Пример #3
0
        public async Task <LogoutOutput> ExecuteAsync(string logoutId)
        {
            bool showLogoutPrompt;

            if (!IsAccountAuthenticated())
            {
                showLogoutPrompt = false;
            }
            else
            {
                var logoutRequest = await _logoutService.GetLogoutRequestAsync(logoutId);

                showLogoutPrompt = logoutRequest?.ShowSignOutPrompt ?? true;
            }

            return(new LogoutOutput(logoutId, showLogoutPrompt));
        }
Пример #4
0
        public async Task GetLogoutRequestAsync_Should_Return_LogoutRequest()
        {
            const string logoutId = "logoutId";
            var          identityServerLogoutRequest = new IdentityServer4.Models.LogoutRequest("iframeUrl", new IdentityServer4.Models.LogoutMessage());
            var          logoutRequest = new LogoutRequest(identityServerLogoutRequest.ShowSignoutPrompt,
                                                           identityServerLogoutRequest.PostLogoutRedirectUri, identityServerLogoutRequest.SignOutIFrameUrl, null, null);

            _identityServerInteractionServiceMock.Setup(x => x.GetLogoutContextAsync(It.IsAny <string>()))
            .ReturnsAsync(identityServerLogoutRequest);
            _mapperMock.Setup(x =>
                              x.Map <IdentityServer4.Models.LogoutRequest, LogoutRequest>(
                                  It.IsAny <IdentityServer4.Models.LogoutRequest>())).Returns(logoutRequest);

            var result = await _service.GetLogoutRequestAsync(logoutId);

            result.Should().BeEquivalentTo(logoutRequest);
        }