LANCommander/LANCommander.Launcher/UI/Components/Authentication/AuthenticationProviderDialog.razor
Pat Hartl 698a7523b6 Code cleanup
- Move all Launcher components to LANCommander.Launcher.UI namespace
- Move all SCSS files next to components (when possible)
- Refactor styles that control overflow of content into titlebar to MainWindow only
- Remove use in launcher UI of SDK.Client
2025-12-31 20:01:04 -06:00

55 lines
No EOL
1.7 KiB
Text

@using LANCommander.SDK.Models
@using Newtonsoft.Json
@using Photino.NET
@namespace LANCommander.Launcher.UI
@inject IConnectionClient ConnectionClient
@inject AuthenticationClient AuthenticationClient
@inject IMessageService MessageService
@inject ILogger<AuthenticationProviderDialog> Logger
@inject LocalizationService LocalizationService
@code {
[Parameter] public EventCallback<AuthToken> OnTokenReceived { get; set; }
Uri AuthenticationProviderLoginUrl;
PhotinoWindow Window;
public async Task Open(Uri baseUrl, AuthenticationProvider authenticationProvider)
{
await ConnectionClient.UpdateServerAddressAsync(baseUrl);
AuthenticationProviderLoginUrl = AuthenticationClient.GetAuthenticationProviderLoginUrl(authenticationProvider.Slug);
Window = new PhotinoWindow()
.SetTitle(LocalizationService.GetString("SignInUsingProvider", authenticationProvider.Name))
.Load(AuthenticationProviderLoginUrl)
.SetContextMenuEnabled(false);
Window.RegisterWebMessageReceivedHandler(MessageHandler);
Window.WaitForClose();
}
async void MessageHandler(object? sender, string message)
{
try
{
var token = JsonConvert.DeserializeObject<AuthToken>(message);
await InvokeAsync(() =>
{
OnTokenReceived.InvokeAsync(token);
});
}
catch (Exception ex)
{
Logger.LogError(ex, "Could not process login");
MessageService.Error(LocalizationService.GetString("CouldNotProcessLogin"));
}
finally
{
Window.Close();
}
}
}