static async Task Main(string[] args) { Console.WriteLine("Hello World!"); Stopwatch a = new Stopwatch(); a.Start(); var data = new LoginUserCommand { Email = "*****@*****.**", Password = "******" }; ApiHelper api = new ApiHelper("https://localhost:44348/"); var result = await api.PostAsync <Result <LoginUserViewModel> >("api/Account/login", data); var accessToken = result.Data.Token; Console.WriteLine(accessToken); api.AddJwtAuthorization(accessToken); //var allProducts = await apiAuth.GetAsync<Result<IEnumerable<ProductViewModel>>>("api/v1/Product"); var productOne = await api.GetAsync <Result <ProductViewModel> >("api/v1/Product/1"); var productTwo = await api.GetAsync <Result <ProductViewModel> >("api/v1/Product/2"); api.RemoveJwtAuthorization(); var productThree = await api.GetAsync <Result <ProductViewModel> >("api/v1/Product/3"); await api.GetAsync <Result <ProductViewModel> >("api/v1/Product/3"); a.Stop(); Console.WriteLine(a.ElapsedMilliseconds); Console.ReadLine(); }
internal static void Authenticate(LoggedInUser data, string accessToken) { Name = $"{data.FirstName} {data.LastName}"; UserName = data.UserName; FirstName = data.FirstName; LastName = data.LastName; Email = data.Email; PhoneNumber = data.PhoneNumber; Roles = data.Roles; ApiHelper = new ApiHelper(ApplicationSettings.ApiBaseAddress); ApiHelper.AddJwtAuthorization(data.Token); IsAuthenticated = true; if (data.Roles.Any(a => a == AuthorizationConstants.Roles.Administrator.ToString())) { IsAdmin = true; } }
private async void loginButton_Click(object sender, RoutedEventArgs e) { loginButton.IsEnabled = false; loginRing.IsActive = true; var data = new LoginUserCommand { Email = email.Text, Password = password.Password }; ApiHelper api = new ApiHelper(ApplicationSettings.ApiBaseAddress); try { var result = await api.PostAsync <Result <LoggedInUser> >("api/Account/login", data); if (result.Succeeded) { var accessToken = result.Data.Token; api.AddJwtAuthorization(accessToken); //await Dialog.InformationDialogResult("Success!", result.Messages[0]); SessionContext.Authenticate(result.Data, accessToken); Dashboard dashboard = new Dashboard(); //dashboard.header.Text = $"welcome, {email.Text}"; dashboard.Show(); var myWindow = Window.GetWindow(this); myWindow.Close(); this.SwitchTheme(this, ref dashboard); } else { await Dialog.InformationDialog("Failed!", result.Messages[0]); } } catch (Exception ex) { await Dialog.InformationDialog("Exception!", ex.Message); } finally { loginButton.IsEnabled = true; loginRing.IsActive = false; } }