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

PAS-536 | Add support for AuthenticatorDisplayName #713

Merged
merged 9 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion src/AdminConsole/AdminConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.5.0" />
<PackageReference Include="Passwordless.AspNetCore" Version="2.1.0-beta.2" />
<PackageReference Include="Passwordless.AspNetCore" Version="2.1.0-beta.3" />
<PackageReference Include="Stripe.net" Version="41.*" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 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,7 +53,8 @@
<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="AaGuid" Value="@cred.AaGuid" class="sm:col-span-2" />
<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="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: 28 additions & 69 deletions src/AdminConsole/Components/Shared/Credentials.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@ public partial class Credentials : ComponentBase
{
public const string ManageCredentialFormName = "manage-credential-form";

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();
}
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() ?? [];

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

public bool? IsDiscoverable { get; }

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

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

private string? _subtitle;

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

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

internal static class StringExtensions
{
public static string? NullIfEmpty(this string? value) =>
!string.IsNullOrEmpty(value) ? value : null;
}
Loading
Loading