postit: harden oidc settings defaults on startup
This commit is contained in:
parent
0ba44c21e7
commit
148a3aa271
1 changed files with 24 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue