Add auto redirect to provider to launcher
This commit is contained in:
parent
f5c5bbee70
commit
42ca077416
5 changed files with 41 additions and 1 deletions
|
|
@ -52,6 +52,9 @@ public partial class LoginViewModel : ViewModelBase
|
|||
[ObservableProperty]
|
||||
private bool _isServerOffline;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _autoRedirectToProvider;
|
||||
|
||||
public ObservableCollection<AuthenticationProvider> AuthenticationProviders { get; } = new();
|
||||
|
||||
public event EventHandler? LoginSucceeded;
|
||||
|
|
@ -94,6 +97,18 @@ public partial class LoginViewModel : ViewModelBase
|
|||
|
||||
if (!AllowRegistration && IsRegistering)
|
||||
IsRegistering = false;
|
||||
|
||||
AutoRedirectToProvider = await _authenticationClient.GetAutoRedirectToProviderAsync();
|
||||
}
|
||||
|
||||
public async Task TryAutoRedirectToProviderAsync()
|
||||
{
|
||||
if (IsServerOffline || !AutoRedirectToProvider || IsLoading)
|
||||
return;
|
||||
|
||||
// Mirror server behavior: only auto-challenge when exactly one provider exists.
|
||||
if (AuthenticationProviders.Count == 1)
|
||||
await LoginWithProviderAsync(AuthenticationProviders[0]);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
|
|
|||
|
|
@ -181,8 +181,12 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
|
||||
if (serverOnline)
|
||||
await LoginViewModel.LoadAuthenticationProvidersAsync();
|
||||
|
||||
|
||||
CurrentView = LoginViewModel;
|
||||
|
||||
if (serverOnline)
|
||||
await LoginViewModel.TryAutoRedirectToProviderAsync();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -196,6 +200,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
LoginViewModel.IsServerOffline = false;
|
||||
await LoginViewModel.LoadAuthenticationProvidersAsync();
|
||||
CurrentView = LoginViewModel;
|
||||
await LoginViewModel.TryAutoRedirectToProviderAsync();
|
||||
}
|
||||
|
||||
private async void OnLoginSucceeded(object? sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -210,6 +210,24 @@ public class AuthenticationClient(
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<bool> GetAutoRedirectToProviderAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = await apiRequestFactory
|
||||
.Create()
|
||||
.UseRoute("/api/Settings")
|
||||
.GetAsync<Settings>();
|
||||
|
||||
return settings?.Authentication?.AutoRedirectToProvider ?? false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Older servers don't expose this setting - default to no auto-redirect
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Uri GetAuthenticationProviderLoginUrl(string provider)
|
||||
{
|
||||
return connectionClient.GetServerAddress().Join($"api/Auth/Login?Provider={provider}");
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ public class AuthenticationSettings
|
|||
public AuthToken Token { get; set; }
|
||||
public bool OfflineModeEnabled { get; set; }
|
||||
public bool AllowRegistration { get; set; } = true;
|
||||
public bool AutoRedirectToProvider { get; set; } = false;
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ public static class SettingsEndpoints
|
|||
Authentication = new
|
||||
{
|
||||
AllowRegistration = settingsProvider.CurrentValue.Server.Authentication.AllowRegistration,
|
||||
AutoRedirectToProvider = settingsProvider.CurrentValue.Server.Authentication.AutoRedirectToProvider,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue