postit: harden oidc settings defaults on startup

This commit is contained in:
Paul Schneider 2026-09-06 16:20:17 +01:00
commit 148a3aa271

View file

@ -123,6 +123,8 @@ public partial class Settings : ViewModelBase
// build options from a torn read.
lock (_mutationGate)
{
EnsureAuthenticationDefaultsLocked();
var options = new OidcClientOptions
{
Authority = Authentication.Authority,
@ -151,6 +153,25 @@ public partial class Settings : ViewModelBase
}
}
private void EnsureAuthenticationDefaultsLocked()
{
Authentication ??= new AuthenticationSettings();
if (string.IsNullOrWhiteSpace(Authentication.Authority))
Authentication.Authority = AuthenticationSettings.DefaultAuthority;
if (string.IsNullOrWhiteSpace(Authentication.ClientId))
Authentication.ClientId = AuthenticationSettings.DefaultClientId;
if (string.IsNullOrWhiteSpace(Authentication.RedirectUri))
Authentication.RedirectUri = AuthenticationSettings.DesktopRedirectUri;
if (Authentication.Scopes is null || Authentication.Scopes.Length == 0)
Authentication.Scopes = AuthenticationSettings.DefaultScopes;
Authentication.RefreshScopeListText();
}
/// <summary>
/// Scopes the PostIt client always requires from the OIDC provider,
/// regardless of what the user has in their settings file.
@ -334,11 +355,13 @@ public partial class Settings : ViewModelBase
AuthenticationSettings.DesktopRedirectUri : settings.Authentication.RedirectUri;
if (settings.Authentication.Scopes is null || settings.Authentication.Scopes.Length == 0)
{
settings.Authentication.Scopes = AuthenticationSettings.DefaultScopes;
this.Authentication.Scopes = AuthenticationSettings.DefaultScopes;
}
else
this.Authentication.Scopes = settings.Authentication.Scopes;
}
EnsureAuthenticationDefaultsLocked();
}
// A disk load (or an embedded-resource fallback) is the
// baseline, not a user edit. Clear the dirty flag last