Esempio n. 1
0
        private BankIdLoginViewModel GetLoginViewModel(string returnUrl, string loginOptions, BankIdLoginOptions unprotectedLoginOptions, AntiforgeryTokenSet antiforgeryTokens)
        {
            var loginScriptOptions = new BankIdLoginScriptOptions
            {
                RefreshIntervalMs = BankIdAuthenticationDefaults.StatusRefreshIntervalMs,

                InitialStatusMessage = _bankIdUserMessageLocalizer.GetLocalizedString(MessageShortName.RFA13),
                UnknownErrorMessage  = _bankIdUserMessageLocalizer.GetLocalizedString(MessageShortName.RFA22),

                UnsupportedBrowserErrorMessage = _localizer["UnsupportedBrowser_ErrorMessage"],

                BankIdInitializeApiUrl = Url.Action(nameof(BankIdApiController.InitializeAsync), "BankIdApi"),
                BankIdStatusApiUrl     = Url.Action(nameof(BankIdApiController.StatusAsync), "BankIdApi")
            };

            return(new BankIdLoginViewModel
            {
                ReturnUrl = returnUrl,

                AutoLogin = unprotectedLoginOptions.IsAutoLogin(),
                PersonalIdentityNumber = unprotectedLoginOptions.PersonalIdentityNumber?.To12DigitString() ?? string.Empty,

                LoginOptions = loginOptions,
                UnprotectedLoginOptions = unprotectedLoginOptions,

                AntiXsrfRequestToken = antiforgeryTokens.RequestToken,
                LoginScriptOptions = loginScriptOptions,
                LoginScriptOptionsJson = SystemRuntimeJsonSerializer.Serialize(loginScriptOptions)
            });
        }
Esempio n. 2
0
        private BankIdLoginViewModel GetLoginViewModel(string returnUrl, string loginOptions, BankIdLoginOptions unprotectedLoginOptions, AntiforgeryTokenSet antiforgeryTokens)
        {
            var initialStatusMessage = GetInitialStatusMessage(unprotectedLoginOptions);
            var loginScriptOptions   = new BankIdLoginScriptOptions(
                Url.Action("Initialize", "BankIdApi"),
                Url.Action("Status", "BankIdApi"),
                Url.Action("Cancel", "BankIdApi")
                )
            {
                RefreshIntervalMs = BankIdDefaults.StatusRefreshIntervalMs,

                InitialStatusMessage = _bankIdUserMessageLocalizer.GetLocalizedString(initialStatusMessage),
                UnknownErrorMessage  = _bankIdUserMessageLocalizer.GetLocalizedString(MessageShortName.RFA22),

                UnsupportedBrowserErrorMessage = _localizer["UnsupportedBrowser_ErrorMessage"]
            };

            return(new BankIdLoginViewModel(
                       returnUrl,
                       Url.Content(unprotectedLoginOptions.CancelReturnUrl),
                       unprotectedLoginOptions.IsAutoLogin(),
                       unprotectedLoginOptions.PersonalIdentityNumber?.To12DigitString() ?? string.Empty,
                       loginOptions,
                       unprotectedLoginOptions,
                       loginScriptOptions,
                       SystemRuntimeJsonSerializer.Serialize(loginScriptOptions),
                       antiforgeryTokens.RequestToken
                       ));
        }
Esempio n. 3
0
        public static async Task <TResult> GetAsync <TResult>(this HttpClient httpClient, string url)
        {
            var httpResponseMessage = await httpClient.GetAsync(url);

            var content = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);

            return(SystemRuntimeJsonSerializer.Deserialize <TResult>(content));
        }
Esempio n. 4
0
        public static async Task <TResult> PostAsync <TResult>(this HttpClient httpClient, string url, Dictionary <string, string?> postData)
        {
            var requestContent = GetFormUrlEncodedContent(postData);

            var httpResponseMessage = await httpClient.PostAsync(url, requestContent).ConfigureAwait(false);

            var content = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);

            return(SystemRuntimeJsonSerializer.Deserialize <TResult>(content));
        }
Esempio n. 5
0
        public static async Task <TResult> PostAsync <TRequest, TResult>(this HttpClient httpClient, string url, TRequest request)
        {
            var requestJson    = SystemRuntimeJsonSerializer.Serialize(request);
            var requestContent = GetJsonStringContent(requestJson);

            var httpResponseMessage = await httpClient.PostAsync(url, requestContent).ConfigureAwait(false);

            await BankIdApiErrorHandler.EnsureSuccessAsync(httpResponseMessage).ConfigureAwait(false);

            var content = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);

            return(SystemRuntimeJsonSerializer.Deserialize <TResult>(content));
        }
        public static async Task <TResult> GetAsync <TResult>(this HttpClient httpClient, string url)
        {
            var httpResponseMessage = await httpClient.GetAsync(url);

            var content = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var deserialized = SystemRuntimeJsonSerializer.Deserialize <TResult>(content);

            if (deserialized == null)
            {
                throw new Exception("Could not deserialize JSON response");
            }

            return(deserialized);
        }
        public static async Task <TResult> PostAsync <TResult>(this HttpClient httpClient, string url, Dictionary <string, string?> postData)
        {
            var requestContent = GetFormUrlEncodedContent(postData);

            var httpResponseMessage = await httpClient.PostAsync(url, requestContent).ConfigureAwait(false);

            var content = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var deserialized = SystemRuntimeJsonSerializer.Deserialize <TResult>(content);

            if (deserialized == null)
            {
                throw new Exception("Could not deserialize JSON response");
            }

            return(deserialized);
        }
        private static async Task <Error> TryGetErrorAsync(HttpResponseMessage httpResponseMessage)
        {
            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                try
                {
                    var content = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                    return(SystemRuntimeJsonSerializer.Deserialize <Error>(content));
                }
                catch (Exception)
                {
                    // Intentionally left empty
                }
            }

            return(null);
        }