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

Feature/blazor wasm #379

Merged
merged 12 commits into from
Jul 28, 2023
Prev Previous commit
Next Next commit
Blazor Client: Update userservice for new featues
Regenhardt committed Jun 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8703de3a96c9ef4e32f99f093f5af62c3057b61b
53 changes: 43 additions & 10 deletions BlazorWasmDemo/Server/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -104,11 +104,21 @@ public CredentialCreateOptions GetCredentialOptions([FromRoute] string? username

// 4. Create options
var options = _fido2.RequestNewCredential(
user,
user,
existingKeys,
authenticatorSelection,
attestationType ?? AttestationConveyancePreference.None
);
authenticatorSelection,
attestationType ?? AttestationConveyancePreference.None,
new AuthenticationExtensionsClientInputs()
{
Extensions = true,
UserVerificationMethod = true,
CredProps = true,
DevicePubKey = new AuthenticationExtensionsDevicePublicKeyInputs()
{
Attestation = attestationType?.ToString() ?? AttestationConveyancePreference.None.ToString()
},
}
);

// 5. Temporarily store options, session/in-memory cache/redis/db
_pendingCredentials[key] = options;
@@ -150,13 +160,21 @@ public async Task<string> CreateCredentialAsync([FromRoute] string username, [Fr
// 4. Store the credentials in db
_demoStorage.AddCredentialToUser(options.User, new StoredCredential
{
Descriptor = new PublicKeyCredentialDescriptor(result.Result.CredentialId),
Type = result.Result.Type,
CredType = result.Result.CredType,
Id = result.Result.Id,
Descriptor = new PublicKeyCredentialDescriptor(result.Result.Id),
PublicKey = result.Result.PublicKey,
UserHandle = result.Result.User.Id,
SignatureCounter = result.Result.Counter,
CredType = result.Result.CredType,
SignCount = result.Result.Counter,
RegDate = DateTime.Now,
AaGuid = result.Result.AaGuid
AaGuid = result.Result.AaGuid,
DevicePublicKeys = new List<byte[]> { result.Result.DevicePublicKey },
Transports = result.Result.Transports,
BE = result.Result.BE,
BS = result.Result.BS,
AttestationObject = result.Result.AttestationObject,
AttestationClientDataJSON = result.Result.AttestationClientDataJSON,
});

// 5. Now we need to remove the options from the pending dictionary
@@ -193,8 +211,18 @@ public AssertionOptions MakeAssertionOptions([FromRoute] string? username, [From
existingKeys = _demoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();
}

// 2. Create options (usernameless users will be prompted by their device to select a credential from their own list)
var options = _fido2.GetAssertionOptions(existingKeys, userVerification ?? UserVerificationRequirement.Discouraged);
var exts = new AuthenticationExtensionsClientInputs()
{
UserVerificationMethod = true,
Extensions = true,
DevicePubKey = new AuthenticationExtensionsDevicePublicKeyInputs()
};

// 2. Create options (usernameless users will be prompted by their device to select a credential from their own list)
var options = _fido2.GetAssertionOptions(
existingKeys,
userVerification ?? UserVerificationRequirement.Discouraged,
exts);

// 4. Temporarily store options, session/in-memory cache/redis/db
_pendingAssertions[new string(options.Challenge.Select(b => (char)b).ToArray())] = options;
@@ -248,6 +276,7 @@ public async Task<string> MakeAssertionAsync([FromBody] AuthenticatorAssertionRa
clientResponse,
options,
creds.PublicKey,
creds.DevicePublicKeys,
creds.SignatureCounter,
UserHandleOwnerOfCredentialIdAsync,
cancellationToken: cancellationToken);
@@ -256,6 +285,10 @@ public async Task<string> MakeAssertionAsync([FromBody] AuthenticatorAssertionRa
if (res.Status == "ok")
{
_demoStorage.UpdateCounter(res.CredentialId, res.Counter);
if (res.DevicePublicKey is not null)
{
creds.DevicePublicKeys.Add(res.DevicePublicKey);
}
}
else
{