Esempio n. 1
0
        public async Task <IActionResult> Callback()
        {
            var scpAuthenticationResponse = await _scpAuthenticationProcessor.ProcessScpAuthenticationAsync();

            if (!scpAuthenticationResponse.IsSuccessful)
            {
                return(this.RedirectToErrorPage());
            }
            var user = scpAuthenticationResponse.InsolvencyUser;

            HttpContext.SetAuditDetail(new AuditDetail()
            {
                Email          = user.Email,
                Name           = user.Name,
                ActionName     = nameof(Callback),
                ControllerName = nameof(AccountController),
                ClientId       = "AuthorizationServer",
                OrganisationId = $"ScpGroupId-{user.ScpGroupId}",
                SenderName     = "INSS.Identity"
            });
            await _iIdentityManagementRepository.CompleteOnboardingForPendingOrganisationsAsync(user.Email, user.ScpGroupId);

            var organisationsThatUserIsPartOf = await _iIdentityManagementRepository.GetOrganisationByScpGroupIdAsync(user.ScpGroupId);

            if (!organisationsThatUserIsPartOf.Any())
            {
                await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);

                return(this.RedirectToAccessDeniedPage());
            }

            await HttpContext.SignInAsync(scpAuthenticationResponse.InsolvencyUser, scpAuthenticationResponse.AuthenticationProperties);

            await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);

            var context = await _interaction.GetAuthorizationContextAsync(scpAuthenticationResponse.ReturnUrl);

            await _events.RaiseAsync(new UserLoginSuccessEvent(Constants.ScpAuthenticationSchemeAlias, scpAuthenticationResponse.InsolvencyUser.SubjectId, scpAuthenticationResponse.InsolvencyUser.SubjectId, scpAuthenticationResponse.InsolvencyUser.SubjectId, true, context?.Client.ClientId));

            return(Redirect(scpAuthenticationResponse.ReturnUrl));
        }