Exemplo n.º 1
0
        private async Task LoadSharedKeyAndQrCodeUriAsync()
        {
            var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

            var response = client.GetAsync("api/Identity/LoadSharedKeyAndQrCodeUri").Result;

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(await response.Content.ReadAsStringAsync());
            }

            SharedKeyInfo = JsonConvert.DeserializeObject <SharedKeyInfo>(await response.Content.ReadAsStringAsync());
        }
Exemplo n.º 2
0
        private async Task ForgetBrowserAsync()
        {
            try
            {
                var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

                await ApplicationUserService.ForgetBrowserAsync(client);

                await ToastService.ShowToastAsync("The current browser has been forgotten. When you login again from this browser you will be prompted for your 2fa code.", ToastType.Success);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
            }
        }
Exemplo n.º 3
0
        private async Task DeletePersonalDataAsync()
        {
            try
            {
                await ButtonSpinner.SpinAsync(async() =>
                {
                    var client            = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);
                    List <string> cookies = null;
                    if (client.DefaultRequestHeaders.TryGetValues("Cookie", out IEnumerable <string> cookieEntries))
                    {
                        cookies = cookieEntries.ToList();
                    }

                    var response = await client.PostAsync("api/Identity/DeletePersonalData", (new StringContent(JsonConvert.SerializeObject(PasswordModel), Encoding.UTF8, "application/json")));

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new Exception(await response.Content.ReadAsStringAsync());
                    }

                    if (cookies != null && cookies.Any())
                    {
                        client.DefaultRequestHeaders.Remove("Cookie");

                        foreach (var cookie in cookies[0].Split(';'))
                        {
                            var cookieParts = cookie.Split('=');
                            await JSRuntime.InvokeVoidAsync("removeCookie", cookieParts[0]);
                        }
                    }

                    NavigationManager.NavigateTo(Routes.Login, true);
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
Exemplo n.º 4
0
        private async Task VerifyTwoFactorAsync()
        {
            try
            {
                var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

                var response = await client.PostAsync("api/Identity/VerifyTwoFactor", (new StringContent(JsonConvert.SerializeObject(VerificationCode), Encoding.UTF8, "application/json")));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }

                var verifyTwoFactorTokenInfo = JsonConvert.DeserializeObject <VerifyTwoFactorInfo>(await response.Content.ReadAsStringAsync());

                if (!verifyTwoFactorTokenInfo.IsTwoFactorTokenValid)
                {
                    await ToastService.ShowToastAsync("Verification code is invalid.", ToastType.Error);

                    return;
                }

                await ToastService.ShowToastAsync("Your authenticator app has been verified.", ToastType.Success);

                if (verifyTwoFactorTokenInfo.RecoveryCodes != null)
                {
                    RecoveryCodes = verifyTwoFactorTokenInfo.RecoveryCodes.ToArray();
                }
                else
                {
                    await ModalDialogClose();
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
Exemplo n.º 5
0
        private async Task ResetAuthenticatorKeyAsync()
        {
            try
            {
                var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

                var response = await client.PostAsync("api/Identity/ResetAuthenticatorKey", new StringContent(string.Empty));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }

                await ToastService.ShowToastAsync("Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.", ToastType.Success);
                await ModalDialogClose();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
Exemplo n.º 6
0
        private async Task DisableTwoFactorAsync()
        {
            try
            {
                var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

                var response = await client.PostAsync("api/Identity/DisableTwoFactor", new StringContent(string.Empty));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }

                await ToastService.ShowToastAsync("2fa has been disabled. You can reenable 2fa when you setup an authenticator app", ToastType.Success);
                await ModalDialogClose();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
Exemplo n.º 7
0
        private async Task GenerateRecoveryCodesAsync()
        {
            try
            {
                var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

                var response = await client.PostAsync("api/Identity/GenerateNewTwoFactorRecoveryCodes", new StringContent(string.Empty));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }

                var recoveryCodes = JsonConvert.DeserializeObject <List <string> >(await response.Content.ReadAsStringAsync());

                RecoveryCodes = recoveryCodes.ToArray();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
Exemplo n.º 8
0
        private async Task GetTwoFactorInfoAsync()
        {
            var client = await HttpClientHelper.CreateClientAsync(NavigationManager, HttpClientFactory, JSRuntime, Logger);

            TwoFactorInfo = await ApplicationUserService.GetTwoFactorInfoAsync(client);
        }