1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -05:00

[PM-4168] update keys for WebAuthnLoginCredential (#3506)

* allow update of webauthnlogincredential

* Added Tests

* fixed tests to use commands

* addressing various feedback items
This commit is contained in:
Ike
2023-12-15 13:38:34 -08:00
committed by GitHub
parent d488ebec0f
commit 767c58466c
8 changed files with 286 additions and 22 deletions

View File

@ -34,4 +34,26 @@ public class WebAuthnCredentialRepository : Repository<Core.Auth.Entities.WebAut
return Mapper.Map<List<Core.Auth.Entities.WebAuthnCredential>>(creds);
}
}
public async Task<bool> UpdateAsync(Core.Auth.Entities.WebAuthnCredential credential)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var cred = await dbContext.WebAuthnCredentials
.FirstOrDefaultAsync(d => d.Id == credential.Id &&
d.UserId == credential.UserId);
if (cred == null)
{
return false;
}
cred.EncryptedPrivateKey = credential.EncryptedPrivateKey;
cred.EncryptedPublicKey = credential.EncryptedPublicKey;
cred.EncryptedUserKey = credential.EncryptedUserKey;
await dbContext.SaveChangesAsync();
return true;
}
}
}