public async Task <bool> Login(LoginModel model) { var request = new HttpRequestMessage(HttpMethod.Post, Endpoints.LoginEndpoint); request.Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var client = _client.CreateClient(); HttpResponseMessage response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { return(false); } var content = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <TokenResponse>(content); await _localStorage.SetItemAsync("authToken", token.Token); await _authenticationStateProvider.LoggedIn(); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", token.Token); return(true); }
public async Task <bool> Login(LoginModel user) { HttpRequestMessage request = new(HttpMethod.Post, Endpoints.LoginrUrl); request.Content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json"); var client = _httpClient.CreateClient(); HttpResponseMessage response = await client.SendAsync(request); if (response.IsSuccessStatusCode == false) { return(false); } // get the Token from the response //var content = await response.Content.ReadAsStringAsync(); var content = "{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2RhbmdhamF0IjoiMzI4OCIsInN1YiI6InZBbGV4IiwiZW1haWwiOiJhbGV4QGdtYWlsLmNvbSIsInJvbGUiOiJBZG1pbiIsIkRhdGUiOiIxNS0wOS0yMDIxIDE0OjA0OjE3IiwianRpIjoiNWNhN2FhNzktNTRiNC00Y2FkLWIxMWEtNWU3NzE5MWVmYWUxIiwiZXhwIjoxNjMxNzA3NDU3LCJpc3MiOiJQZXNvbmFsQWNjaWRlbnRAZ2FyYW50YS5jb20iLCJhdWQiOiJQZXNvbmFsQWNjaWRlbnRZ2FyYW50YS5jb20ifQ.yQKccCQVuGFw6_RInGfX8jnzNFC6h36HI9VMXHrOHa4\"}"; var token = JsonConvert.DeserializeObject <TokenResponse>(content); // Store token await _localStorage.SetItemAsync("authToken", token.Token); // Change State of the app await _authStateProvider.LoggedIn(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token.Token); return(true); }
public async Task <bool> Login(LoginModel user) { var response = await _client.PostAsJsonAsync(Endpoints.LoginrUrl, user); if (response.IsSuccessStatusCode == false) { return(false); } // get the Token from the response var content = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <TokenResponse>(content); // Store token await _localStorage.SetItemAsync("authToken", token.Token); // Change State of the app await _authStateProvider.LoggedIn(); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token.Token); return(true); }
public async Task <bool> Login(LoginModel model) { var response = await _client.PostAsJsonAsync(Endpoints.LoginEndpoint, model); if (!response.IsSuccessStatusCode) { return(false); } var content = await response.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <TokenResponse>(content); await _localStorage.SetItemAsync("authToken", token.Token); await _authenticationStateProvider.LoggedIn(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", token.Token); return(true); }