1
0
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:
Kyle Spearrin
2017-06-21 16:55:45 -04:00
parent 50c0b3e752
commit 0c84f9c151
9 changed files with 179 additions and 0 deletions

View 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
}
}
}

View 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);
}
}

View 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();
}
}
}