mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
api for requesting installation ids
This commit is contained in:
parent
5576028c7a
commit
a2dc1602f8
32
src/Api/Controllers/InstallationsController.cs
Normal file
32
src/Api/Controllers/InstallationsController.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Api.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
[Route("installations")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
public class InstallationsController : Controller
|
||||
{
|
||||
private readonly IInstallationRepository _installationRepository;
|
||||
|
||||
public InstallationsController(
|
||||
IInstallationRepository installationRepository)
|
||||
{
|
||||
_installationRepository = installationRepository;
|
||||
}
|
||||
|
||||
[HttpPost("")]
|
||||
[AllowAnonymous]
|
||||
public async Task<InstallationResponseModel> Post([FromBody] InstallationRequestModel model)
|
||||
{
|
||||
var installation = model.ToInstallation();
|
||||
await _installationRepository.CreateAsync(installation);
|
||||
return new InstallationResponseModel(installation);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
"globalSettings": {
|
||||
"selfHosted": false,
|
||||
"siteName": "bitwarden",
|
||||
"projectName": "Api",
|
||||
"projectName": "Api",
|
||||
"stripeApiKey": "SECRET",
|
||||
"baseServiceUri": {
|
||||
"vault": "http://localhost:4001",
|
||||
@ -111,6 +111,11 @@
|
||||
"Endpoint": "get:/alive",
|
||||
"Period": "1m",
|
||||
"Limit": 5
|
||||
},
|
||||
{
|
||||
"Endpoint": "post:/installations",
|
||||
"Period": "2m",
|
||||
"Limit": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
|
22
src/Core/Models/Api/Request/InstallationRequestModel.cs
Normal file
22
src/Core/Models/Api/Request/InstallationRequestModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class InstallationRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
|
||||
public Installation ToInstallation()
|
||||
{
|
||||
return new Installation
|
||||
{
|
||||
Key = Utilities.CoreHelpers.SecureRandomString(20),
|
||||
Email = Email,
|
||||
Enabled = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
18
src/Core/Models/Api/Response/InstallationResponseModel.cs
Normal file
18
src/Core/Models/Api/Response/InstallationResponseModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class InstallationResponseModel : ResponseModel
|
||||
{
|
||||
public InstallationResponseModel(Installation installation)
|
||||
: base("installation")
|
||||
{
|
||||
Id = installation.Id.ToString();
|
||||
Key = installation.Key;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Key { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user