@using LANCommander.SDK.Models @using Newtonsoft.Json @using Photino.NET @inject SDK.Client Client @inject IMessageService MessageService @inject ILogger Logger @inject LocalizationService LocalizationService @code { [Parameter] public EventCallback OnTokenReceived { get; set; } Uri AuthenticationProviderLoginUrl; PhotinoWindow Window; public async Task Open(Uri baseUrl, AuthenticationProvider authenticationProvider) { await Client.Connection.UpdateServerAddressAsync(baseUrl); AuthenticationProviderLoginUrl = Client.Authentication.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(message); await InvokeAsync(() => { OnTokenReceived.InvokeAsync(token); }); } catch (Exception ex) { Logger.LogError(ex, "Could not process login"); MessageService.Error(LocalizationService.GetString("CouldNotProcessLogin")); } finally { Window.Close(); } } }