/// <summary> /// Войти через AADB2C /// </summary> public async Task <bool> LoginWithMicrosoftAsync() { var succeeded = false; try { var result = await App.AuthenticationClient.AcquireTokenAsync( new[] { AppSettings.B2cClientId }, string.Empty, UiOptions.SelectAccount, string.Empty, null, $"{AppSettings.B2cAuthority}{AppSettings.B2cTenant}", AppSettings.B2cPolicy); var user = AuthenticationResultHelper.GetUserFromResult(result); user.AvatarUrl = _avatarProvider.GetAvatarUrl(user.Email); user.LoggedInWithMicrosoftAccount = true; AppSettings.User = user; succeeded = true; } catch (MsalException ex) { if (ex.ErrorCode != MsalError.AuthenticationCanceled) { System.Diagnostics.Debug.WriteLine($"Ошибка при аутентификации MSAL: {ex}"); throw new ServiceAuthenticationException(); } } return(succeeded); }
/// <summary> /// Сохранить результат входа /// </summary> private void SaveAuthenticationResult(AuthenticationResult result) { var user = AuthenticationResultHelper.GetUserFromResult(result); user.AvatarUrl = _avatarProvider.GetAvatarUrl(user.Email); AppSettings.User = user; }