working on server authenticate users
This commit is contained in:
@@ -1,18 +1,49 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using RelayShared.Services;
|
||||
|
||||
namespace RelayClient;
|
||||
|
||||
public class ServerAPI
|
||||
{
|
||||
static HttpClient client = new HttpClient { BaseAddress = new Uri("http://localhost:5000/") };
|
||||
static HttpClient client = new HttpClient { BaseAddress = new Uri("http://192.168.1.85:5000/") };
|
||||
static HttpClient core = new HttpClient { BaseAddress = new Uri("http://192.168.1.85:1337/") };
|
||||
|
||||
public static void setupClient()
|
||||
public static async Task setupClient()
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
core.DefaultRequestHeaders.Accept.Clear();
|
||||
core.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
core.DefaultRequestHeaders.Add("User-Agent", "RelayClient");
|
||||
MainPage._userToken = await CoreUserSignin(new AuthSignin
|
||||
{
|
||||
UserName = MainPage._username,
|
||||
Password = "password"
|
||||
});
|
||||
|
||||
await CoreUserAlive(new AuthSignin
|
||||
{
|
||||
UserName = MainPage._username,
|
||||
Password = MainPage._userToken
|
||||
});
|
||||
}
|
||||
|
||||
public static async Task<Uri> CoreUserAlive(AuthSignin data)
|
||||
{
|
||||
HttpResponseMessage response = await core.PostAsJsonAsync("user/isAlive", data);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return response.Headers.Location;
|
||||
}
|
||||
|
||||
public static async Task<string> CoreUserSignin(AuthSignin data)
|
||||
{
|
||||
HttpResponseMessage response = await core.PostAsJsonAsync("user/signin", data);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public static async Task<Uri> PostOfferAsync(DBOffer offer)
|
||||
|
||||
Reference in New Issue
Block a user