mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-19 10:49:34 -04:00
The dialog names the account in full because it is shown to whoever owns it, but log files get attached to public issue reports, which is why the codebase has MaskedLogEntry. Naming the account in the log the same way the dialog does would have put real email addresses into every shared log. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Dinah.Core;
|
|
|
|
namespace AudibleUtilities;
|
|
|
|
/// <summary>Describes whether an account has usable stored Audible tokens.</summary>
|
|
public static class AccountCredentialStatus
|
|
{
|
|
/// <summary>
|
|
/// True when identity tokens are absent or carry no refresh token, meaning the account was never fully logged
|
|
/// in or its credentials were cleared, rather than merely holding an expired access token.
|
|
/// </summary>
|
|
public static bool LooksLikeMissingCredentials(Account? account)
|
|
{
|
|
if (account?.IdentityTokens is not { } tokens)
|
|
return true;
|
|
|
|
if (tokens.IsValid)
|
|
return false;
|
|
|
|
// without a refresh token there is nothing to renew from, so this needs a fresh login rather than a retry
|
|
return string.IsNullOrWhiteSpace(tokens.RefreshToken?.Value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Account label for dialogs shown to the person who owns the account. Not for logs: those get attached to
|
|
/// public issue reports, which is what <see cref="Account.MaskedLogEntry"/> is for.
|
|
/// </summary>
|
|
public static string FormatAccountLabel(Account? account)
|
|
{
|
|
if (account is null)
|
|
return "an Audible account";
|
|
|
|
return string.IsNullOrWhiteSpace(account.AccountName) || account.AccountName.EqualsInsensitive(account.AccountId)
|
|
? $"'{account.AccountId}'"
|
|
: $"'{account.AccountName}' ({account.AccountId})";
|
|
}
|
|
}
|