Skip to content

Commit

Permalink
IEnumerable -> IReadOnlyList
Browse files Browse the repository at this point in the history
  • Loading branch information
joegoldman2 committed Oct 26, 2023
1 parent fddae56 commit 366891f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion BlazorWasmDemo/Client/Shared/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public UserService(HttpClient httpClient, WebAuthn webAuthn)
{
Console.WriteLine(e);
var errorMessage = e.Message;
if (options.ExcludeCredentials?.Any() ?? false)
if (options.ExcludeCredentials?.Count > 0)
{
errorMessage += " (You may have already registered this device)";
}
Expand Down
2 changes: 1 addition & 1 deletion BlazorWasmDemo/Server/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public UserController(IFido2 fido2)
});

// 2. Get user existing keys by username
var existingKeys = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingKeys = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

// 3. Build authenticator selection
var authenticatorSelection = AuthenticatorSelection.Default;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private string FormatException(Exception e)
});

// 2. Get user existing keys by username
var existingKeys = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingKeys = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

// 3. Create options
var authenticatorSelection = new AuthenticatorSelection
Expand Down
4 changes: 2 additions & 2 deletions Demo/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public JsonResult MakeCredentialOptionsTest([FromBody] TEST_MakeCredentialParams
});

// 2. Get user existing keys by username
var existingKeys = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingKeys = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

//var exts = new AuthenticationExtensionsClientInputs() { Extensions = true, UserVerificationIndex = true, Location = true, UserVerificationMethod = true, BiometricAuthenticatorPerformanceBounds = new AuthenticatorBiometricPerfBounds { FAR = float.MaxValue, FRR = float.MaxValue } };
var exts = new AuthenticationExtensionsClientInputs() { };
Expand Down Expand Up @@ -122,7 +122,7 @@ public IActionResult AssertionOptionsTest([FromBody] TEST_AssertionClientParams
return NotFound("username was not registered");

// 2. Get registered credentials from database
var existingCredentials = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingCredentials = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

var uv = assertionClientParams.UserVerification;
if (null != assertionClientParams.authenticatorSelection)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var user = DemoStorage.GetOrAddUser(username, () => new User
});

// 2. Get user existing keys by username
var existingKeys = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingKeys = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

// 3. Create options
var options = _lib.RequestNewCredential(user, existingKeys, AuthenticatorSelection.Default, AttestationConveyancePreference.Parse(attType));
Expand Down Expand Up @@ -153,7 +153,7 @@ var user = DemoStorage.GetUser(username);
if (user == null) return NotFound("username was not registered");

// 2. Get registered credentials from database
var existingCredentials = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor);
var existingCredentials = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

// 3. Create options
var options = _lib.GetAssertionOptions(
Expand Down
9 changes: 7 additions & 2 deletions Src/Fido2.Models/AssertionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AssertionOptions : Fido2ResponseBase
/// This OPTIONAL member contains a list of PublicKeyCredentialDescriptor objects representing public key credentials acceptable to the caller, in descending order of the caller’s preference(the first item in the list is the most preferred credential, and so on down the list)
/// </summary>
[JsonPropertyName("allowCredentials")]
public IEnumerable<PublicKeyCredentialDescriptor> AllowCredentials { get; set; }
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowCredentials { get; set; } = new List<PublicKeyCredentialDescriptor>();

/// <summary>
/// This member describes the Relying Party's requirements regarding user verification for the get() operation. Eligible authenticators are filtered to only those capable of satisfying this requirement
Expand All @@ -51,7 +51,12 @@ public class AssertionOptions : Fido2ResponseBase
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AuthenticationExtensionsClientInputs Extensions { get; set; }

public static AssertionOptions Create(Fido2Configuration config, byte[] challenge, IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials, UserVerificationRequirement? userVerification, AuthenticationExtensionsClientInputs extensions)
public static AssertionOptions Create(
Fido2Configuration config,
byte[] challenge,
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
UserVerificationRequirement? userVerification,
AuthenticationExtensionsClientInputs extensions)
{
return new AssertionOptions()
{
Expand Down
14 changes: 10 additions & 4 deletions Src/Fido2.Models/CredentialCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -62,7 +61,7 @@ public sealed class CredentialCreateOptions : Fido2ResponseBase
/// This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator.The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.
/// </summary>
[JsonPropertyName("excludeCredentials")]
public IEnumerable<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; } = Enumerable.Empty<PublicKeyCredentialDescriptor>();
public IReadOnlyList<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; } = new List<PublicKeyCredentialDescriptor>();

/// <summary>
/// This OPTIONAL member contains additional parameters requesting additional processing by the client and authenticator. For example, if transaction confirmation is sought from the user, then the prompt string might be included as an extension.
Expand All @@ -71,7 +70,14 @@ public sealed class CredentialCreateOptions : Fido2ResponseBase
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AuthenticationExtensionsClientInputs Extensions { get; set; }

public static CredentialCreateOptions Create(Fido2Configuration config, byte[] challenge, Fido2User user, AuthenticatorSelection authenticatorSelection, AttestationConveyancePreference attestationConveyancePreference, IEnumerable<PublicKeyCredentialDescriptor> excludeCredentials, AuthenticationExtensionsClientInputs extensions)
public static CredentialCreateOptions Create(
Fido2Configuration config,
byte[] challenge,
Fido2User user,
AuthenticatorSelection authenticatorSelection,
AttestationConveyancePreference attestationConveyancePreference,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticationExtensionsClientInputs extensions)
{
return new CredentialCreateOptions
{
Expand All @@ -97,7 +103,7 @@ public static CredentialCreateOptions Create(Fido2Configuration config, byte[] c
},
AuthenticatorSelection = authenticatorSelection,
Attestation = attestationConveyancePreference,
ExcludeCredentials = excludeCredentials ?? Enumerable.Empty<PublicKeyCredentialDescriptor>(),
ExcludeCredentials = excludeCredentials ?? Array.Empty<PublicKeyCredentialDescriptor>(),
Extensions = extensions
};
}
Expand Down
6 changes: 3 additions & 3 deletions Src/Fido2/Fido2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Fido2 : IFido2
/// <param name="excludeCredentials">Recommended. This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator.The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.</param>
public CredentialCreateOptions RequestNewCredential(
Fido2User user,
IEnumerable<PublicKeyCredentialDescriptor> excludeCredentials,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticationExtensionsClientInputs? extensions = null)
{
return RequestNewCredential(user, excludeCredentials, AuthenticatorSelection.Default, AttestationConveyancePreference.None, extensions);
Expand All @@ -44,7 +44,7 @@ public class Fido2 : IFido2
/// <param name="excludeCredentials">Recommended. This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator.The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.</param>
public CredentialCreateOptions RequestNewCredential(
Fido2User user,
IEnumerable<PublicKeyCredentialDescriptor> excludeCredentials,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticatorSelection authenticatorSelection,
AttestationConveyancePreference attestationPreference,
AuthenticationExtensionsClientInputs? extensions = null)
Expand Down Expand Up @@ -84,7 +84,7 @@ public class Fido2 : IFido2
/// </summary>
/// <returns></returns>
public AssertionOptions GetAssertionOptions(
IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials,
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
UserVerificationRequirement? userVerification,
AuthenticationExtensionsClientInputs? extensions = null)
{
Expand Down
8 changes: 4 additions & 4 deletions Src/Fido2/IFido2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Fido2NetLib;
public interface IFido2
{
AssertionOptions GetAssertionOptions(
IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials,
UserVerificationRequirement? userVerification,
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
UserVerificationRequirement? userVerification,
AuthenticationExtensionsClientInputs? extensions = null);

Task<VerifyAssertionResult> MakeAssertionAsync(
Expand All @@ -30,12 +30,12 @@ public interface IFido2

CredentialCreateOptions RequestNewCredential(
Fido2User user,
IEnumerable<PublicKeyCredentialDescriptor> excludeCredentials,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticationExtensionsClientInputs? extensions = null);

CredentialCreateOptions RequestNewCredential(
Fido2User user,
IEnumerable<PublicKeyCredentialDescriptor> excludeCredentials,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticatorSelection authenticatorSelection,
AttestationConveyancePreference attestationPreference,
AuthenticationExtensionsClientInputs? extensions = null);
Expand Down

0 comments on commit 366891f

Please sign in to comment.