refactoring the login

This commit is contained in:
Paul Schneider 2026-06-20 15:01:03 +01:00
commit 2fd799c09f
13 changed files with 129 additions and 196 deletions

View file

@ -107,44 +107,6 @@ public partial class MainPageViewModel : ViewModelBase
ApplyFilter();
}
[RelayCommand]
internal async Task Login()
{
await ExecuteAsync(async () =>
{
// Try interactive OIDC login first
try
{
var loginWin = new PostIt.Views.LoginPage();
var result = await loginWin.StartLoginAsync(Settings.GetOidcClientOptions());
if (result is not null && !result.IsError && !string.IsNullOrWhiteSpace(result.AccessToken))
{
BearerToken = result.AccessToken;
StatusMessage = "Interactive token acquired.";
return;
}
}
catch
{
// ignore and fallback to client credentials
}
// Fallback to client credentials if interactive fails
var tokenResponse = await RequestClientCredentialsTokenAsync();
if (string.IsNullOrWhiteSpace(tokenResponse.AccessToken))
{
throw new InvalidOperationException("Failed to acquire a token using client credentials.");
}
BearerToken = tokenResponse.AccessToken;
StatusMessage = string.IsNullOrWhiteSpace(tokenResponse.Error)
? "Bearer token acquired (client credentials)."
: $"Token acquired with warning: {tokenResponse.ErrorDescription}";
});
}
[RelayCommand]
internal async Task Save()
{