Untitled

mail@pastecode.io avatar
unknown
plain_text
4 years ago
1.1 kB
38
Indexable
Never
public async Task<(bool,string)> Authenticate(Authentication model)
        {
            try
            {
                var tokenBased = string.Empty;
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Clear();
                    client.BaseAddress = new Uri(WebAPIUrl);
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(mediaType: "application/json"));

                    var responseMessage = await client.PostAsJsonAsync<Authentication>(requestUri: "/api/Authentification/Authenticate", model);

                    var resultMessage = responseMessage.Content.ReadAsStringAsync().Result;
                    tokenBased = JsonConvert.DeserializeObject<string>(resultMessage);

                    return (responseMessage.IsSuccessStatusCode, tokenBased);
                }
            }
            catch (Exception)
            {

                throw;
            }
            
        }