Exemplo n.º 1
0
        public async Task <ActionResult> Status(BankIdLoginApiStatusRequest request)
        {
            var unprotectedLoginOptions = _loginOptionsProtector.Unprotect(request.LoginOptions);
            var orderRef = _orderRefProtector.Unprotect(request.OrderRef);

            CollectResponse collectResponse;

            try
            {
                collectResponse = await _bankIdApiClient.CollectAsync(orderRef.OrderRef);
            }
            catch (BankIdApiException bankIdApiException)
            {
                _logger.BankIdCollectFailure(orderRef.OrderRef, bankIdApiException);
                var errorStatusMessage = GetStatusMessage(bankIdApiException);
                return(BadRequest(new BankIdLoginApiErrorResponse(errorStatusMessage)));
            }

            var statusMessage = GetStatusMessage(collectResponse, unprotectedLoginOptions, HttpContext.Request);

            if (collectResponse.GetCollectStatus() == CollectStatus.Pending)
            {
                return(CollectPending(collectResponse, statusMessage));
            }

            if (collectResponse.GetCollectStatus() == CollectStatus.Complete)
            {
                return(await CollectComplete(request, collectResponse));
            }

            return(CollectFailure(collectResponse, statusMessage));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Status(BankIdLoginApiStatusRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.LoginOptions))
            {
                throw new ArgumentNullException(nameof(request.LoginOptions));
            }

            if (string.IsNullOrWhiteSpace(request.ReturnUrl))
            {
                throw new ArgumentNullException(nameof(request.ReturnUrl));
            }

            if (string.IsNullOrWhiteSpace(request.OrderRef))
            {
                throw new ArgumentNullException(nameof(request.OrderRef));
            }

            var unprotectedLoginOptions = _loginOptionsProtector.Unprotect(request.LoginOptions);
            var orderRef       = _orderRefProtector.Unprotect(request.OrderRef);
            var detectedDevice = GetDetectedUserDevice();

            CollectResponse collectResponse;

            try
            {
                collectResponse = await _bankIdApiClient.CollectAsync(orderRef.OrderRef);
            }
            catch (BankIdApiException bankIdApiException)
            {
                await _bankIdEventTrigger.TriggerAsync(new BankIdCollectErrorEvent(orderRef.OrderRef, bankIdApiException, detectedDevice, unprotectedLoginOptions));

                var errorStatusMessage = GetStatusMessage(bankIdApiException);
                return(BadRequestJsonResult(new BankIdLoginApiErrorResponse(errorStatusMessage)));
            }

            var statusMessage = GetStatusMessage(collectResponse, unprotectedLoginOptions, detectedDevice);

            if (collectResponse.GetCollectStatus() == CollectStatus.Pending)
            {
                return(await CollectPending(collectResponse, statusMessage, detectedDevice, unprotectedLoginOptions));
            }

            if (collectResponse.GetCollectStatus() == CollectStatus.Complete)
            {
                return(await CollectComplete(request, collectResponse, detectedDevice, unprotectedLoginOptions));
            }

            var hintCode = collectResponse.GetCollectHintCode();

            if (hintCode.Equals(CollectHintCode.StartFailed) &&
                request.AutoStartAttempts < BankIdConstants.MaxRetryLoginAttempts)
            {
                return(OkJsonResult(BankIdLoginApiStatusResponse.Retry(statusMessage)));
            }

            return(await CollectFailure(collectResponse, statusMessage, detectedDevice, unprotectedLoginOptions));
        }
        public async Task <ActionResult> Status(BankIdLoginApiStatusRequest request)
        {
            if (request.LoginOptions == null)
            {
                throw new ArgumentNullException(nameof(request.LoginOptions));
            }

            if (request.OrderRef == null)
            {
                throw new ArgumentNullException(nameof(request.OrderRef));
            }

            var unprotectedLoginOptions = _loginOptionsProtector.Unprotect(request.LoginOptions);
            var orderRef = _orderRefProtector.Unprotect(request.OrderRef);

            CollectResponse collectResponse;

            try
            {
                collectResponse = await _bankIdApiClient.CollectAsync(orderRef.OrderRef);
            }
            catch (BankIdApiException bankIdApiException)
            {
                _logger.BankIdCollectFailure(orderRef.OrderRef, bankIdApiException);
                var errorStatusMessage = GetStatusMessage(bankIdApiException);
                return(BadRequest(new BankIdLoginApiErrorResponse(errorStatusMessage)));
            }

            var statusMessage = GetStatusMessage(collectResponse, unprotectedLoginOptions, HttpContext.Request);

            if (collectResponse.GetCollectStatus() == CollectStatus.Pending)
            {
                return(CollectPending(collectResponse, statusMessage));
            }

            if (collectResponse.GetCollectStatus() == CollectStatus.Complete)
            {
                return(await CollectComplete(request, collectResponse));
            }

            var hintCode = collectResponse.GetCollectHintCode();

            if (hintCode.Equals(CollectHintCode.StartFailed) &&
                request.AutoStartAttempts < MaxRetryLoginAttempts)
            {
                return(Ok(BankIdLoginApiStatusResponse.Retry(statusMessage)));
            }

            return(CollectFailure(collectResponse, statusMessage));
        }
        public async Task <ActionResult> StatusAsync(BankIdLoginApiStatusRequest request)
        {
            var             orderRef = _orderRefProtector.Unprotect(request.OrderRef);
            CollectResponse collectResponse;

            try
            {
                collectResponse = await _bankIdApiClient.CollectAsync(orderRef.OrderRef);
            }
            catch (BankIdApiException bankIdApiException)
            {
                _logger.BankIdCollectFailure(orderRef.OrderRef, bankIdApiException);
                var errorStatusMessage = GetStatusMessage(bankIdApiException);
                return(BadRequest(new BankIdLoginApiErrorResponse(errorStatusMessage)));
            }

            var statusMessage = GetStatusMessage(collectResponse);

            if (collectResponse.Status == CollectStatus.Pending)
            {
                _logger.BankIdCollectPending(collectResponse.OrderRef, collectResponse.HintCode);
                return(Ok(BankIdLoginApiStatusResponse.Pending(statusMessage)));
            }

            if (collectResponse.Status == CollectStatus.Complete)
            {
                _logger.BankIdCollectCompleted(collectResponse.OrderRef, collectResponse.CompletionData);
                await _bankIdResultStore.StoreCollectCompletedCompletionData(collectResponse.OrderRef, collectResponse.CompletionData);

                var returnUri = GetSuccessReturnUri(collectResponse.CompletionData.User, request.ReturnUrl);
                if (!Url.IsLocalUrl(returnUri))
                {
                    throw new Exception(BankIdAuthenticationConstants.InvalidReturnUrlErrorMessage);
                }

                return(Ok(BankIdLoginApiStatusResponse.Finished(returnUri)));
            }

            _logger.BankIdCollectFailure(collectResponse.OrderRef, collectResponse.HintCode);
            return(BadRequest(new BankIdLoginApiErrorResponse(statusMessage)));
        }