mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
add support for storing u2f challenges
This commit is contained in:
20
src/Core/Models/Table/U2f.cs
Normal file
20
src/Core/Models/Table/U2f.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Models.Table
|
||||
{
|
||||
public class U2f : IDataObject<int>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string KeyHandle { get; set; }
|
||||
public string Challenge { get; set; }
|
||||
public string AppId { get; set; }
|
||||
public string Version { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
// do nothing since it is an identity
|
||||
}
|
||||
}
|
||||
}
|
13
src/Core/Repositories/IU2fRepository.cs
Normal file
13
src/Core/Repositories/IU2fRepository.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IU2fRepository : IRepository<U2f, int>
|
||||
{
|
||||
Task<ICollection<U2f>> GetManyByUserIdAsync(Guid userId);
|
||||
Task DeleteManyByUserIdAsync(Guid userId);
|
||||
}
|
||||
}
|
66
src/Core/Repositories/SqlServer/U2fRepository.cs
Normal file
66
src/Core/Repositories/SqlServer/U2fRepository.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
public class U2fRepository : Repository<U2f, int>, IU2fRepository
|
||||
{
|
||||
public U2fRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString)
|
||||
{ }
|
||||
|
||||
public U2fRepository(string connectionString)
|
||||
: base(connectionString)
|
||||
{ }
|
||||
|
||||
public async Task<ICollection<U2f>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<U2f>(
|
||||
$"[{Schema}].[U2f_ReadByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
$"[{Schema}].[U2f_DeleteByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public override Task<U2f> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task ReplaceAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task UpsertAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task DeleteAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user