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

apikey apis for orgs

This commit is contained in:
Kyle Spearrin
2019-03-04 09:52:43 -05:00
parent 6922cff638
commit 42b104bc8f
5 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
{
public class ApiKeyRequestModel
{
[Required]
public string MasterPasswordHash { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
{
public class ApiKeyResponseModel : ResponseModel
{
public ApiKeyResponseModel(Organization organization, string obj = "apiKey")
: base(obj)
{
if(organization == null)
{
throw new ArgumentNullException(nameof(organization));
}
ApiKey = organization.ApiKey;
}
public string ApiKey { get; set; }
}
}

View File

@ -43,5 +43,6 @@ namespace Bit.Core.Services
Task<OrganizationLicense> GenerateLicenseAsync(Organization organization, Guid installationId);
Task ImportAsync(Guid organizationId, Guid importingUserId, IEnumerable<ImportedGroup> groups,
IEnumerable<ImportedOrganizationUser> newUsers, IEnumerable<string> removeUserExternalIds);
Task RotateApiKeyAsync(Organization organization);
}
}

View File

@ -1341,6 +1341,13 @@ namespace Bit.Core.Services
}
}
public async Task RotateApiKeyAsync(Organization organization)
{
organization.ApiKey = CoreHelpers.SecureRandomString(30);
organization.RevisionDate = DateTime.UtcNow;
await ReplaceAndUpdateCache(organization);
}
private async Task UpdateUsersAsync(Group group, HashSet<string> groupUsers,
Dictionary<string, Guid> existingUsersIdDict, HashSet<Guid> existingUsers = null)
{