Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "PAS-536 | Add support for AuthenticatorDisplayName" #747

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/AdminConsole/Components/Shared/Credentials.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dl class="mt-2">
<CardSummaryProperty Label="Created:" Value="cred.CreatedAt"></CardSummaryProperty>
<CardSummaryProperty Label="Last used:" Value="cred.LastUsedAt"></CardSummaryProperty>

@if (!HideDetails)
{
<div class="credential-card-summary-footer">
Expand Down Expand Up @@ -53,8 +53,7 @@
<CardDetailsProperty Label="Counter" Value="@cred.SignatureCounter" class="sm:col-span-1" />
<CardDetailsProperty Label="RPID" Value="@cred.RPID" class="sm:col-span-1" />
<CardDetailsProperty Label="Origin" Value="@cred.Origin" class="sm:col-span-1" />
<CardDetailsProperty Label="Authenticator" Value="@(cred.AuthenticatorName ?? "<unknown>")" class="sm:col-span-1" />
<CardDetailsProperty Label="AaGuid" Value="@cred.AaGuid" class="sm:col-span-1" />
<CardDetailsProperty Label="AaGuid" Value="@cred.AaGuid" class="sm:col-span-2" />
<CardDetailsProperty Label="Discoverable" Value="@(cred.IsDiscoverable.HasValue ? cred.IsDiscoverable.Value : "Unknown")" class="sm:col-span-1" />
<CardDetailsProperty Label="Backup State / Synced" Value="@(cred.BackupState.HasValue ? cred.BackupState.Value : "Unknown")" class="sm:col-span-1" />
<CardDetailsProperty Label="Backup Eligibility" Value="@(cred.IsBackupEligible.HasValue ? cred.IsBackupEligible.Value : "Unknown")" class="sm:col-span-1" />
Expand Down
97 changes: 69 additions & 28 deletions src/AdminConsole/Components/Shared/Credentials.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ public partial class Credentials : ComponentBase
{
public const string ManageCredentialFormName = "manage-credential-form";

public required IReadOnlyCollection<Credential>? Items { get; set; }

public IReadOnlyCollection<CredentialModel> GetItems() =>
Items?.Select(x => new CredentialModel(
x.Descriptor.Id,
x.PublicKey,
x.SignatureCounter,
x.AttestationFmt,
x.CreatedAt,
x.AaGuid,
x.LastUsedAt,
x.RpId,
x.Origin,
x.Device,
x.Nickname,
x.BackupState,
x.IsBackupEligible,
x.IsDiscoverable,
x.AuthenticatorDisplayName ?? AuthenticatorDataProvider.GetName(x.AaGuid))
).ToArray() ?? [];
public required IReadOnlyCollection<Credential> Items { get; set; }

public IReadOnlyCollection<CredentialModel> GetItems()
{
return Items.Select(x =>
{
var viewModel = new CredentialModel(
x.Descriptor.Id,
x.PublicKey,
x.SignatureCounter,
x.AttestationFmt,
x.CreatedAt,
x.AaGuid,
x.LastUsedAt,
x.RpId,
x.Origin,
x.Device,
x.Nickname,
x.BackupState,
x.IsBackupEligible,
x.IsDiscoverable,
AuthenticatorDataProvider.GetName(x.AaGuid));
return viewModel;
}).ToList();
}

/// <summary>
/// Determines whether the details of the credentials should be hidden.
Expand Down Expand Up @@ -97,7 +102,7 @@ public record CredentialModel

public bool? IsDiscoverable { get; }

public string? AuthenticatorName { get; set; }
public string AuthenticatorName { get; set; }

public bool IsNew()
{
Expand All @@ -107,18 +112,54 @@ public bool IsNew()
/// <summary>
/// The title of the credential card.
/// </summary>
public string Title => AuthenticatorName?.NullIfEmpty() ?? Device.NullIfEmpty() ?? "Passkey";
public string Title
{
get
{
if (IsAuthenticatorKnown)
{
return AuthenticatorName;
}
return string.IsNullOrEmpty(Device) ? "Passkey" : Device;
}
}

private string? _subtitle;

/// <summary>
/// The subtitle of the credential card.
/// The sub title of the credential card.
/// </summary>
public string SubTitle => _subtitle ??= AuthenticatorName switch
public string? SubTitle
{
null => Nickname,
_ => !string.IsNullOrEmpty(Nickname) ? $"{Nickname} on {Device}" : Device
};
get
{
if (_subtitle != null)
{
return _subtitle;
}

if (IsAuthenticatorKnown)
{
if (string.IsNullOrEmpty(Nickname))
{
_subtitle = Device;
}
else
{
var nickname = string.IsNullOrEmpty(Nickname) ? "No nickname" : Nickname;
_subtitle = $"{nickname} on {Device}";
}
}
else
{
_subtitle = Nickname;
}

return _subtitle;
}
}

public bool IsAuthenticatorKnown => AaGuid != Guid.Empty;

public CredentialModel(
byte[] descriptorId,
Expand All @@ -135,7 +176,7 @@ public CredentialModel(
bool? backupState,
bool? isBackupEligible,
bool? isDiscoverable,
string? authenticatorName)
string authenticatorName)
{
DescriptorId = descriptorId.ToBase64Url();
PublicKey = publicKey;
Expand Down
7 changes: 0 additions & 7 deletions src/AdminConsole/Helpers/StringExtensions.cs

This file was deleted.

Loading
Loading