Esempio n. 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));
        }
Esempio n. 2
0
        public async Task <ExternalLoginResultOutput> ExecuteAsync(string scheme)
        {
            var authResult = await _authenticationService.AuthenticateAsync(scheme);

            if (!authResult.Succeeded)
            {
                throw authResult.Failure;
            }

            var emailClaim    = authResult.Principal.FindFirst(ClaimTypes.Email);
            var correlationId = Guid.NewGuid();
            var account       = await _accountProviderService.ProvideAccountForExternalLoginAsync(emailClaim.Value, correlationId);

            if (account.DomainEvents.Any(x => x.GetType() == typeof(AccountCreatedDomainEvent)))
            {
                var pictureClaim = authResult.Principal.FindFirst("picture");
                var picture      = pictureClaim != null ? pictureClaim.Value : string.Empty;
                var accountCreatedIntegrationEvent = new AccountCreatedIntegrationEvent(correlationId, account.Id, account.Email, picture);
                await _integrationEventBus.PublishIntegrationEventAsync(accountCreatedIntegrationEvent);
            }

            var claims = await _accountClaimsCreatorService.CreateAccountClaimsAsync(account);

            var externalSignInTask = _signInService.ExternalSignInAsync(account.Id, account.Email, scheme, claims);
            var signOutTask        = _signOutService.SignOutAsync(scheme);

            var returnUrl =
                authResult.Items is null || !authResult.Items.ContainsKey("returnUrl") ||
                string.IsNullOrWhiteSpace(authResult.Items["returnUrl"])
                    ? "~/"
                    : authResult.Items["returnUrl"];

            var authRequest = await _authorizationService.GetAuthorizationRequestAsync(returnUrl);

            await Task.WhenAll(externalSignInTask, signOutTask);

            return(new ExternalLoginResultOutput(returnUrl, authRequest?.IsNativeClient));
        }
Esempio n. 3
0
        public async Task <IActionResult> LogOut()
        {
            await signOutService.SignOutAsync();

            return(RedirectToAction("Overview", "Home"));
        }