mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00
public and private keys added to db and user domain. added account APIs got getting and putting keys.
This commit is contained in:
parent
7589f9c933
commit
024ee08907
@ -263,6 +263,22 @@ namespace Bit.Api.Controllers
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPut("keys")]
|
||||||
|
[HttpPost("keys")]
|
||||||
|
public async Task<KeysResponseModel> PutKeys([FromBody]KeysRequestModel model)
|
||||||
|
{
|
||||||
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||||
|
await _userService.SaveUserAsync(model.ToUser(user));
|
||||||
|
return new KeysResponseModel(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("keys")]
|
||||||
|
public async Task<KeysResponseModel> GetKeys()
|
||||||
|
{
|
||||||
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||||
|
return new KeysResponseModel(user);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("delete")]
|
[HttpPost("delete")]
|
||||||
public async Task PostDelete([FromBody]DeleteAccountRequestModel model)
|
public async Task PostDelete([FromBody]DeleteAccountRequestModel model)
|
||||||
{
|
{
|
||||||
|
@ -118,8 +118,13 @@ namespace Bit.Api.IdentityServer
|
|||||||
claims.Add(new Claim("device", device.Identifier));
|
claims.Add(new Claim("device", device.Identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Result = new GrantValidationResult(user.Id.ToString(), "Application", identityProvider: "bitwarden",
|
context.Result = new GrantValidationResult(user.Id.ToString(), "Application",
|
||||||
claims: claims.Count > 0 ? claims : null);
|
identityProvider: "bitwarden",
|
||||||
|
claims: claims.Count > 0 ? claims : null,
|
||||||
|
customResponse: new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "PrivateKey", user.PrivateKey }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildTwoFactorResult(User user, ResourceOwnerPasswordValidationContext context)
|
private void BuildTwoFactorResult(User user, ResourceOwnerPasswordValidationContext context)
|
||||||
@ -139,8 +144,8 @@ namespace Bit.Api.IdentityServer
|
|||||||
|
|
||||||
private void BuildErrorResult(bool twoFactorRequest, ResourceOwnerPasswordValidationContext context)
|
private void BuildErrorResult(bool twoFactorRequest, ResourceOwnerPasswordValidationContext context)
|
||||||
{
|
{
|
||||||
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, customResponse:
|
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant,
|
||||||
new Dictionary<string, object>
|
customResponse: new Dictionary<string, object>
|
||||||
{{
|
{{
|
||||||
"ErrorModel", new ErrorResponseModel(twoFactorRequest ?
|
"ErrorModel", new ErrorResponseModel(twoFactorRequest ?
|
||||||
"Code is not correct. Try again." : "Username or password is incorrect. Try again.")
|
"Code is not correct. Try again." : "Username or password is incorrect. Try again.")
|
||||||
|
23
src/Api/Models/Request/Accounts/KeysRequestModel.cs
Normal file
23
src/Api/Models/Request/Accounts/KeysRequestModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using Bit.Core.Domains;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Bit.Api.Models
|
||||||
|
{
|
||||||
|
public class KeysRequestModel
|
||||||
|
{
|
||||||
|
public string PublicKey { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string PrivateKey { get; set; }
|
||||||
|
|
||||||
|
public User ToUser(User existingUser)
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrWhiteSpace(PublicKey))
|
||||||
|
{
|
||||||
|
existingUser.PublicKey = PublicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
existingUser.PrivateKey = PrivateKey;
|
||||||
|
return existingUser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/Api/Models/Response/KeysResponseModel.cs
Normal file
23
src/Api/Models/Response/KeysResponseModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Domains;
|
||||||
|
|
||||||
|
namespace Bit.Api.Models
|
||||||
|
{
|
||||||
|
public class KeysResponseModel : ResponseModel
|
||||||
|
{
|
||||||
|
public KeysResponseModel(User user)
|
||||||
|
: base("keys")
|
||||||
|
{
|
||||||
|
if(user == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
PublicKey = user.PublicKey;
|
||||||
|
PrivateKey = user.PrivateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PublicKey { get; set; }
|
||||||
|
public string PrivateKey { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,8 @@ namespace Bit.Core.Domains
|
|||||||
public string EquivalentDomains { get; set; }
|
public string EquivalentDomains { get; set; }
|
||||||
public string ExcludedGlobalEquivalentDomains { get; set; }
|
public string ExcludedGlobalEquivalentDomains { get; set; }
|
||||||
public DateTime AccountRevisionDate { get; internal set; } = DateTime.UtcNow;
|
public DateTime AccountRevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||||
|
public string PublicKey { get; set; }
|
||||||
|
public string PrivateKey { get; set; }
|
||||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
[EquivalentDomains] NVARCHAR (MAX) NULL,
|
[EquivalentDomains] NVARCHAR (MAX) NULL,
|
||||||
[ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL,
|
[ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL,
|
||||||
[AccountRevisionDate] DATETIME2 (7) NOT NULL,
|
[AccountRevisionDate] DATETIME2 (7) NOT NULL,
|
||||||
|
[PublicKey] NVARCHAR (MAX) NULL,
|
||||||
|
[PrivateKey] NVARCHAR (MAX) NULL,
|
||||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||||
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
|
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user