Skip to content

Commit

Permalink
fix(desktop): Populate existing authentication configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
VMelnalksnis committed May 20, 2023
1 parent f255d42 commit 4244457
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ <h3>Fixed</h3>
Re-enable deleted currencies for an account when importing transactions in
<a href="https://github.com/VMelnalksnis/Gnomeshade/pull/810">#810</a>
</li>
<li>
Populate existing authentication configuration in desktop app in
<a href="https://github.com/VMelnalksnis/Gnomeshade/pull/811">#811</a>
</li>
</ul>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See LICENSE.txt file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.Extensions.Options;
Expand All @@ -19,6 +21,7 @@ public sealed partial class ApplicationSettingsViewModel : ViewModelBase

/// <summary>Gets or sets a value indicating whether authentication configuration is needed.</summary>
[Notify]
[AlsoNotify(nameof(IsValid))]
private bool _enableAuthentication;

/// <summary>Initializes a new instance of the <see cref="ApplicationSettingsViewModel"/> class.</summary>
Expand Down Expand Up @@ -78,17 +81,24 @@ public async Task UpdateConfiguration()

private async Task<bool> IsValidAsync()
{
var valid = await Gnomeshade.IsValid;
if (!valid)
var tasks = new List<Task<bool>>
{
return false;
}
Gnomeshade.IsValid,
Task.Run(async () => !EnableAuthentication || await Authentication.IsValid),
};

if (!EnableAuthentication)
do
{
return true;
var finished = await Task.WhenAny(tasks);
if (finished.Result is false)
{
return false;
}

tasks.Remove(finished);
}
while (tasks.Any());

return await Authentication.IsValid;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public AuthenticationConfigurationViewModel(
{
_logger = logger;
_httpClient = httpClient;

_authority = optionsMonitor.CurrentValue.Oidc?.Authority?.ToString();
_clientId = optionsMonitor.CurrentValue.Oidc?.ClientId;
_clientSecret = optionsMonitor.CurrentValue.Oidc?.ClientSecret;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class OidcOptions
{
/// <inheritdoc cref="OidcClientOptions.Authority"/>
[Required]
public Uri Authority { get; set; } = null!;
public Uri? Authority { get; set; }

/// <inheritdoc cref="OidcClientOptions.ClientId"/>
[Required]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class OidcOptionsExtensions
/// <returns>An instance of <see cref="OidcClientOptions"/> with the respective properties from <paramref name="options"/>.</returns>
public static OidcClientOptions ToOidcClientOptions(this OidcOptions options) => new()
{
Authority = options.Authority.ToString(),
Authority = options.Authority?.ToString(),
ClientId = options.ClientId,
ClientSecret = options.ClientSecret,
Scope = options.Scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<StackPanel Orientation="Vertical" Spacing="5">
<UserControl Content="{Binding Gnomeshade}" />
<CheckBox IsChecked="{Binding EnableAuthentication}">Enable OIDC provider</CheckBox>
<UserControl IsVisible="{Binding EnableAuthentication}" Content="{Binding Authentication}" />
<UserControl IsEnabled="{Binding EnableAuthentication}" Content="{Binding Authentication}" />

<Button IsEnabled="{Binding IsValid^}" Command="{ReflectionBinding UpdateConfiguration}">
Save
Expand Down

0 comments on commit 4244457

Please sign in to comment.