Skip to content

Commit b7165e0

Browse files
authored
PAS-536 | Add support for AuthenticatorDisplayName (#713)
1 parent 1e05cbb commit b7165e0

15 files changed

+1271
-242
lines changed

src/AdminConsole/Components/Shared/Credentials.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dl class="mt-2">
2424
<CardSummaryProperty Label="Created:" Value="cred.CreatedAt"></CardSummaryProperty>
2525
<CardSummaryProperty Label="Last used:" Value="cred.LastUsedAt"></CardSummaryProperty>
26-
26+
2727
@if (!HideDetails)
2828
{
2929
<div class="credential-card-summary-footer">
@@ -53,7 +53,8 @@
5353
<CardDetailsProperty Label="Counter" Value="@cred.SignatureCounter" class="sm:col-span-1" />
5454
<CardDetailsProperty Label="RPID" Value="@cred.RPID" class="sm:col-span-1" />
5555
<CardDetailsProperty Label="Origin" Value="@cred.Origin" class="sm:col-span-1" />
56-
<CardDetailsProperty Label="AaGuid" Value="@cred.AaGuid" class="sm:col-span-2" />
56+
<CardDetailsProperty Label="Authenticator" Value="@(cred.AuthenticatorName ?? "<unknown>")" class="sm:col-span-1" />
57+
<CardDetailsProperty Label="AaGuid" Value="@cred.AaGuid" class="sm:col-span-1" />
5758
<CardDetailsProperty Label="Discoverable" Value="@(cred.IsDiscoverable.HasValue ? cred.IsDiscoverable.Value : "Unknown")" class="sm:col-span-1" />
5859
<CardDetailsProperty Label="Backup State / Synced" Value="@(cred.BackupState.HasValue ? cred.BackupState.Value : "Unknown")" class="sm:col-span-1" />
5960
<CardDetailsProperty Label="Backup Eligibility" Value="@(cred.IsBackupEligible.HasValue ? cred.IsBackupEligible.Value : "Unknown")" class="sm:col-span-1" />

src/AdminConsole/Components/Shared/Credentials.razor.cs

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,26 @@ public partial class Credentials : ComponentBase
1010
{
1111
public const string ManageCredentialFormName = "manage-credential-form";
1212

13-
public required IReadOnlyCollection<Credential> Items { get; set; }
14-
15-
public IReadOnlyCollection<CredentialModel> GetItems()
16-
{
17-
return Items.Select(x =>
18-
{
19-
var viewModel = new CredentialModel(
20-
x.Descriptor.Id,
21-
x.PublicKey,
22-
x.SignatureCounter,
23-
x.AttestationFmt,
24-
x.CreatedAt,
25-
x.AaGuid,
26-
x.LastUsedAt,
27-
x.RpId,
28-
x.Origin,
29-
x.Device,
30-
x.Nickname,
31-
x.BackupState,
32-
x.IsBackupEligible,
33-
x.IsDiscoverable,
34-
AuthenticatorDataProvider.GetName(x.AaGuid));
35-
return viewModel;
36-
}).ToList();
37-
}
13+
public required IReadOnlyCollection<Credential>? Items { get; set; }
14+
15+
public IReadOnlyCollection<CredentialModel> GetItems() =>
16+
Items?.Select(x => new CredentialModel(
17+
x.Descriptor.Id,
18+
x.PublicKey,
19+
x.SignatureCounter,
20+
x.AttestationFmt,
21+
x.CreatedAt,
22+
x.AaGuid,
23+
x.LastUsedAt,
24+
x.RpId,
25+
x.Origin,
26+
x.Device,
27+
x.Nickname,
28+
x.BackupState,
29+
x.IsBackupEligible,
30+
x.IsDiscoverable,
31+
x.AuthenticatorDisplayName ?? AuthenticatorDataProvider.GetName(x.AaGuid))
32+
).ToArray() ?? [];
3833

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

10398
public bool? IsDiscoverable { get; }
10499

105-
public string AuthenticatorName { get; set; }
100+
public string? AuthenticatorName { get; set; }
106101

107102
public bool IsNew()
108103
{
@@ -112,54 +107,18 @@ public bool IsNew()
112107
/// <summary>
113108
/// The title of the credential card.
114109
/// </summary>
115-
public string Title
116-
{
117-
get
118-
{
119-
if (IsAuthenticatorKnown)
120-
{
121-
return AuthenticatorName;
122-
}
123-
return string.IsNullOrEmpty(Device) ? "Passkey" : Device;
124-
}
125-
}
110+
public string Title => AuthenticatorName?.NullIfEmpty() ?? Device.NullIfEmpty() ?? "Passkey";
126111

127112
private string? _subtitle;
128113

129114
/// <summary>
130-
/// The sub title of the credential card.
115+
/// The subtitle of the credential card.
131116
/// </summary>
132-
public string? SubTitle
117+
public string SubTitle => _subtitle ??= AuthenticatorName switch
133118
{
134-
get
135-
{
136-
if (_subtitle != null)
137-
{
138-
return _subtitle;
139-
}
140-
141-
if (IsAuthenticatorKnown)
142-
{
143-
if (string.IsNullOrEmpty(Nickname))
144-
{
145-
_subtitle = Device;
146-
}
147-
else
148-
{
149-
var nickname = string.IsNullOrEmpty(Nickname) ? "No nickname" : Nickname;
150-
_subtitle = $"{nickname} on {Device}";
151-
}
152-
}
153-
else
154-
{
155-
_subtitle = Nickname;
156-
}
157-
158-
return _subtitle;
159-
}
160-
}
161-
162-
public bool IsAuthenticatorKnown => AaGuid != Guid.Empty;
119+
null => Nickname,
120+
_ => !string.IsNullOrEmpty(Nickname) ? $"{Nickname} on {Device}" : Device
121+
};
163122

164123
public CredentialModel(
165124
byte[] descriptorId,
@@ -176,7 +135,7 @@ public CredentialModel(
176135
bool? backupState,
177136
bool? isBackupEligible,
178137
bool? isDiscoverable,
179-
string authenticatorName)
138+
string? authenticatorName)
180139
{
181140
DescriptorId = descriptorId.ToBase64Url();
182141
PublicKey = publicKey;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Passwordless.AdminConsole.Helpers;
2+
3+
internal static class StringExtensions
4+
{
5+
public static string? NullIfEmpty(this string? value) =>
6+
!string.IsNullOrEmpty(value) ? value : null;
7+
}

0 commit comments

Comments
 (0)