Skip to content
Open
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
1 change: 1 addition & 0 deletions src/Identity/Extensions.Core/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
Microsoft.AspNetCore.Identity.UserPasskeyInfo.Aaguid.get -> byte[]?
Microsoft.AspNetCore.Identity.UserPasskeyInfo.Aaguid.set -> void
Microsoft.AspNetCore.Identity.UserPasskeyInfo.UserPasskeyInfo(byte[]! credentialId, byte[]! publicKey, System.DateTimeOffset createdAt, uint signCount, string![]? transports, bool isUserVerified, bool isBackupEligible, bool isBackedUp, byte[]! attestationObject, byte[]! clientDataJson, string? name) -> void
31 changes: 31 additions & 0 deletions src/Identity/Extensions.Core/src/UserPasskeyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ public UserPasskeyInfo(
bool isBackedUp,
byte[] attestationObject,
byte[] clientDataJson)
: this(credentialId, publicKey, createdAt, signCount, transports, isUserVerified, isBackupEligible, isBackedUp, attestationObject, clientDataJson, name: null)
{
}

/// <summary>
/// Initializes a new instance of <see cref="UserPasskeyInfo"/> with a friendly name.
/// </summary>
/// <param name="credentialId">The credential ID for the passkey.</param>
/// <param name="publicKey">The public key for the passkey.</param>
/// <param name="createdAt">The time when the passkey was created.</param>
/// <param name="signCount">The signature counter for the passkey.</param>
/// <param name="transports">The transports supported by this passkey.</param>
/// <param name="isUserVerified">Indicates if the passkey has a verified user.</param>
/// <param name="isBackupEligible">Indicates if the passkey is eligible for backup.</param>
/// <param name="isBackedUp">Indicates if the passkey is currently backed up.</param>
/// <param name="attestationObject">The passkey's attestation object.</param>
/// <param name="clientDataJson">The passkey's client data JSON.</param>
/// <param name="name">An optional friendly name for the passkey.</param>
public UserPasskeyInfo(
byte[] credentialId,
byte[] publicKey,
DateTimeOffset createdAt,
uint signCount,
string[]? transports,
bool isUserVerified,
bool isBackupEligible,
bool isBackedUp,
byte[] attestationObject,
byte[] clientDataJson,
string? name)
{
CredentialId = credentialId;
PublicKey = publicKey;
Expand All @@ -45,6 +75,7 @@ public UserPasskeyInfo(
IsBackedUp = isBackedUp;
AttestationObject = attestationObject;
ClientDataJson = clientDataJson;
Name = name;
}

/// <summary>
Expand Down
88 changes: 88 additions & 0 deletions src/Identity/test/Identity.Test/UserPasskeyInfoTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Xunit;

namespace Microsoft.AspNetCore.Identity.Test;

public class UserPasskeyInfoTest
{
[Fact]
public void Ctor_WithName_SetsAllProperties()
{
// Arrange
var credentialId = new byte[] { 1, 2, 3 };
var publicKey = new byte[] { 4, 5, 6 };
var createdAt = DateTimeOffset.UtcNow;
var transports = new[] { "usb", "nfc" };
var attestationObject = new byte[] { 7, 8, 9 };
var clientDataJson = new byte[] { 10, 11 };
var name = "My Security Key";

// Act
var passkey = new UserPasskeyInfo(
credentialId,
publicKey,
createdAt,
signCount: 42,
transports,
isUserVerified: true,
isBackupEligible: true,
isBackedUp: false,
attestationObject,
clientDataJson,
name);

// Assert
Assert.Equal(credentialId, passkey.CredentialId);
Assert.Equal(publicKey, passkey.PublicKey);
Assert.Equal(createdAt, passkey.CreatedAt);
Assert.Equal(42u, passkey.SignCount);
Assert.Equal(transports, passkey.Transports);
Assert.True(passkey.IsUserVerified);
Assert.True(passkey.IsBackupEligible);
Assert.False(passkey.IsBackedUp);
Assert.Equal(attestationObject, passkey.AttestationObject);
Assert.Equal(clientDataJson, passkey.ClientDataJson);
Assert.Equal("My Security Key", passkey.Name);
}

[Fact]
public void Ctor_WithNullName_LeavesNameNull()
{
var passkey = new UserPasskeyInfo(
new byte[] { 1 },
new byte[] { 2 },
DateTimeOffset.UtcNow,
signCount: 0,
transports: null,
isUserVerified: false,
isBackupEligible: false,
isBackedUp: false,
new byte[] { 3 },
new byte[] { 4 },
name: null);

Assert.Null(passkey.Name);
}

[Fact]
public void Ctor_WithoutName_LeavesNameNull()
{
// The original constructor should still work and leave Name unset.
var passkey = new UserPasskeyInfo(
new byte[] { 1 },
new byte[] { 2 },
DateTimeOffset.UtcNow,
signCount: 0,
transports: null,
isUserVerified: false,
isBackupEligible: false,
isBackedUp: false,
new byte[] { 3 },
new byte[] { 4 });

Assert.Null(passkey.Name);
}
}
Loading