Esempio n. 1
0
        public async Task <IActionResult> Confirmation()
        {
            try
            {
                logger.ScopeTrace(() => "Start confirmation verification.");

                var verified = await accountActionLogic.VerifyConfirmationAsync();

                var uiLoginUpParty = await tenantRepository.GetAsync <UiLoginUpPartyData>(Sequence.UiUpPartyId);

                securityHeaderLogic.AddImgSrc(uiLoginUpParty.IconUrl);
                securityHeaderLogic.AddImgSrcFromCss(uiLoginUpParty.Css);

                return(View(new ConfirmationViewModel
                {
                    Title = uiLoginUpParty.Title,
                    IconUrl = uiLoginUpParty.IconUrl,
                    Css = uiLoginUpParty.Css,
                    Verified = verified
                }));
            }
            catch (Exception ex)
            {
                throw new EndpointException($"Confirmation failed, Name '{RouteBinding.UpParty.Name}'.", ex)
                      {
                          RouteBinding = RouteBinding
                      };
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> RegTwoFactor()
        {
            try
            {
                logger.ScopeTrace(() => "Start two factor registration.");

                var sequenceData = await sequenceLogic.GetSequenceDataAsync <LoginUpSequenceData>(remove : false);

                loginPageLogic.CheckUpParty(sequenceData);
                if (sequenceData.TwoFactorAppState != TwoFactorAppSequenceStates.DoRegistration)
                {
                    throw new InvalidOperationException($"Invalid {nameof(TwoFactorAppSequenceStates)} is '{sequenceData.TwoFactorAppState}'. Required to be '{TwoFactorAppSequenceStates.DoRegistration}'.");
                }
                if (!sequenceData.EmailVerified)
                {
                    await accountActionLogic.SendConfirmationEmailAsync(sequenceData.Email);

                    return(GetEmailNotConfirmedView());
                }

                var loginUpParty = await tenantRepository.GetAsync <LoginUpParty>(sequenceData.UpPartyId);

                securityHeaderLogic.AddImgSrc(loginUpParty.IconUrl);
                securityHeaderLogic.AddImgSrcFromCss(loginUpParty.Css);

                var twoFactorSetupInfo = await accountTwoFactorLogic.GenerateSetupCodeAsync(loginUpParty.TwoFactorAppName, sequenceData.Email);

                sequenceData.TwoFactorAppNewSecret = twoFactorSetupInfo.Secret;
                await sequenceLogic.SaveSequenceDataAsync(sequenceData);

                return(View(new RegisterTwoFactorViewModel
                {
                    Title = loginUpParty.Title,
                    IconUrl = loginUpParty.IconUrl,
                    Css = loginUpParty.Css,
                    QrCodeSetupImageUrl = twoFactorSetupInfo.QrCodeSetupImageUrl,
                    ManualSetupKey = twoFactorSetupInfo.ManualSetupKey
                }));
            }
            catch (Exception ex)
            {
                throw new EndpointException($"Start two factor registration failed, Name '{RouteBinding.UpParty.Name}'.", ex)
                      {
                          RouteBinding = RouteBinding
                      };
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Login()
        {
            try
            {
                logger.ScopeTrace(() => "Start login.");

                var sequenceData = await sequenceLogic.GetSequenceDataAsync <LoginUpSequenceData>(remove : false);

                loginPageLogic.CheckUpParty(sequenceData);
                var loginUpParty = await tenantRepository.GetAsync <LoginUpParty>(sequenceData.UpPartyId);

                securityHeaderLogic.AddImgSrc(loginUpParty.IconUrl);
                securityHeaderLogic.AddImgSrcFromCss(loginUpParty.Css);

                (var session, var user) = await sessionLogic.GetAndUpdateSessionCheckUserAsync(loginUpParty, GetDownPartyLink(loginUpParty, sequenceData));

                var validSession = session != null && ValidSessionUpAgainstSequence(sequenceData, session, loginPageLogic.GetRequereMfa(user, loginUpParty, sequenceData));
                if (validSession && sequenceData.LoginAction != LoginAction.RequireLogin)
                {
                    return(await loginPageLogic.LoginResponseUpdateSessionAsync(loginUpParty, sequenceData.DownPartyLink, session));
                }

                if (sequenceData.LoginAction == LoginAction.ReadSession)
                {
                    return(await loginUpLogic.LoginResponseErrorAsync(sequenceData, LoginSequenceError.LoginRequired));
                }
                else
                {
                    logger.ScopeTrace(() => "Show login dialog.");
                    return(View(nameof(Login), new LoginViewModel
                    {
                        SequenceString = SequenceString,
                        Title = loginUpParty.Title,
                        IconUrl = loginUpParty.IconUrl,
                        Css = loginUpParty.Css,
                        EnableCancelLogin = loginUpParty.EnableCancelLogin,
                        EnableResetPassword = !loginUpParty.DisableResetPassword,
                        EnableCreateUser = !validSession && loginUpParty.EnableCreateUser,
                        Email = sequenceData.Email.IsNullOrWhiteSpace() ? string.Empty : sequenceData.Email,
                    }));
                }
            }
            catch (Exception ex)
            {
                throw new EndpointException($"Login failed, Name '{RouteBinding.UpParty.Name}'.", ex)
                      {
                          RouteBinding = RouteBinding
                      };
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Index()
        {
            var errorViewModel = new ErrorViewModel
            {
                CreateTime = DateTimeOffset.Now,
                RequestId  = HttpContext.TraceIdentifier
            };

            var exceptionHandlerPathFeature = HttpContext.Features.Get <IExceptionHandlerPathFeature>();
            var exception = exceptionHandlerPathFeature?.Error;

            if (exceptionHandlerPathFeature != null && exceptionHandlerPathFeature.Path.EndsWith($"/{Constants.Routes.OAuthController}/{Constants.Endpoints.Token}", StringComparison.OrdinalIgnoreCase))
            {
                return(HandleOAuthTokenException(exception));
            }

            if (RouteBinding != null && !exceptionHandlerPathFeature.Path.IsNullOrEmpty())
            {
                try
                {
                    var sequenceStartIndex = exceptionHandlerPathFeature.Path.IndexOf('_') + 1;
                    if (exceptionHandlerPathFeature.Path.Length > sequenceStartIndex)
                    {
                        var sequence = await sequenceLogic.TryReadSequenceAsync(exceptionHandlerPathFeature.Path.Substring(sequenceStartIndex));

                        if (sequence != null)
                        {
                            var uiLoginUpParty = await tenantRepository.GetAsync <UiLoginUpPartyData>(sequence.UiUpPartyId);

                            securityHeaderLogic.AddImgSrc(uiLoginUpParty.IconUrl);
                            securityHeaderLogic.AddImgSrcFromCss(uiLoginUpParty.Css);
                            errorViewModel.Title   = uiLoginUpParty.Title;
                            errorViewModel.IconUrl = uiLoginUpParty.IconUrl;
                            errorViewModel.Css     = uiLoginUpParty.Css;
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }
            }

            var sequenceTimeoutException = FindException <SequenceTimeoutException>(exception);

            if (sequenceTimeoutException != null)
            {
                return(HandleSequenceTimeoutException(errorViewModel, sequenceTimeoutException));
            }

            var routeCreationException = FindException <RouteCreationException>(exception);

            if (routeCreationException != null)
            {
                return(HandleRouteCreationException(errorViewModel, routeCreationException));
            }

            var externalKeyIsNotReadyException = FindException <ExternalKeyIsNotReadyException>(exception);

            if (externalKeyIsNotReadyException != null)
            {
                return(HandleexternalKeyIsNotReadyException(errorViewModel));
            }

            if (environment.IsDevelopment())
            {
                errorViewModel.TechnicalErrors = new List <string>(exception.ToString().Split('\n'));
            }
            else
            {
                errorViewModel.TechnicalErrors = exception.GetAllMessages();
            }
            return(View(errorViewModel));
        }