working on server authenticate users
This commit is contained in:
@@ -15,7 +15,8 @@ public partial class App : Application
|
||||
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
throw new Exception("Missing required --user argument. Example: --user Keeper317");
|
||||
username = "Test";
|
||||
// throw new Exception("Missing required --user argument. Example: --user Keeper317");
|
||||
}
|
||||
|
||||
ClientSession.Username = username;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:local="clr-namespace:RelayClient"
|
||||
Title="RelayClient">
|
||||
Title="RelayClient"
|
||||
FlyoutBehavior="Flyout">
|
||||
|
||||
<ShellContent
|
||||
Title="Home"
|
||||
|
||||
@@ -8,10 +8,12 @@ namespace RelayClient;
|
||||
|
||||
public partial class MainPage : ContentPage
|
||||
{
|
||||
private readonly string _username;
|
||||
public static string _username;
|
||||
private readonly RelaySocketClient _socket;
|
||||
private readonly RtcBridgeService _rtc;
|
||||
|
||||
public static string? _userToken;
|
||||
|
||||
private string? _currentChannelId;
|
||||
private string? _currentChannelName;
|
||||
|
||||
@@ -23,6 +25,7 @@ public partial class MainPage : ContentPage
|
||||
InitializeComponent();
|
||||
|
||||
_username = username;
|
||||
|
||||
UserLabel.Text = $"Logged in as: {_username}";
|
||||
|
||||
if (!KeyStorage.HasKeys(_username))
|
||||
@@ -32,7 +35,7 @@ public partial class MainPage : ContentPage
|
||||
KeyStorage.SavePublicKey(_username, keys.publicKey);
|
||||
}
|
||||
|
||||
ServerAPI.setupClient();
|
||||
var waitFor = ServerAPI.setupClient();
|
||||
|
||||
_socket = new RelaySocketClient(_username);
|
||||
_rtc = new RtcBridgeService(
|
||||
@@ -56,6 +59,8 @@ public partial class MainPage : ContentPage
|
||||
});
|
||||
};
|
||||
|
||||
// while(!waitFor.IsCompleted){}
|
||||
|
||||
_socket.Connect();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed class RelaySocketClient
|
||||
public event Action<string>? ServerPublicKeyReceived;
|
||||
public event Action<string>? Log;
|
||||
|
||||
public RelaySocketClient(string username, string url = "ws://localhost:1337/")
|
||||
public RelaySocketClient(string username, string url = "ws://192.168.1.85:5001/")
|
||||
{
|
||||
_username = username;
|
||||
_socket = new WebSocket(url);
|
||||
@@ -32,6 +32,7 @@ public sealed class RelaySocketClient
|
||||
|
||||
var publicKey = KeyStorage.LoadPublicKey(_username);
|
||||
|
||||
SendRaw($"AUTHENTICATE_USER|{_username}|{MainPage._userToken}");
|
||||
SendRaw($"REGISTER_KEY|{_username}|{publicKey}");
|
||||
SendRaw("GET_SERVER_KEY");
|
||||
SendRaw("GET_CHANNELS");
|
||||
|
||||
Reference in New Issue
Block a user