コード例 #1
0
        public async Task <IActionResult> CheckLoginApproval(LoginAttemptInputModel model, CancellationToken cancellationToken)
        {
            var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);

            var returnUrl = context != null ? model.ReturnUrl : GetLocalReturnUrl(model.ReturnUrl);

            var loginAttempt = await _mediator.Send(new GetLoginAttemptQuery(model.Id), cancellationToken);

            if ((loginAttempt == null || loginAttempt.Status == LoginAttemptStatus.Expired) && context != null)
            {
                await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);
            }

            if (loginAttempt?.Status == LoginAttemptStatus.Approved)
            {
                await _mediator.Send(new DoLoginCommand(loginAttempt.Id, model.RememberLogin, context?.Client.ClientId), cancellationToken);
            }

            return(Json(new
            {
                Approved = loginAttempt?.Status == LoginAttemptStatus.Approved,
                Expired = loginAttempt == null || loginAttempt.Status == LoginAttemptStatus.Expired,
                ReturnUrl = returnUrl
            }));
        }
コード例 #2
0
        public async Task <IActionResult> WaitForLoginApproval(LoginAttemptInputModel model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var loginAttempt = await _mediator.Send(new GetLoginAttemptQuery(model.Id), cancellationToken);

            if (loginAttempt == null)
            {
                return(await CancelLogin(model.ReturnUrl));
            }

            return(View("WaitForLoginApproval", new LoginAttemptViewModel
            {
                ReturnUrl = model.ReturnUrl,
                RememberLogin = model.RememberLogin,
                Id = loginAttempt.Id,
                ExpiryDate = loginAttempt.ExpiryDate
            }));
        }