mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
[SM-501] Add support for revoking access tokens (#2692)
* Add support for revoking access tokens
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
using Bit.Core.SecretsManager.Commands.ServiceAccounts.Interfaces;
|
||||
using Bit.Core.SecretsManager.Entities;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
|
||||
namespace Bit.Commercial.Core.SecretsManager.Commands.ServiceAccounts;
|
||||
|
||||
public class RevokeAccessTokensCommand : IRevokeAccessTokensCommand
|
||||
{
|
||||
private readonly IApiKeyRepository _apiKeyRepository;
|
||||
|
||||
public RevokeAccessTokensCommand(IApiKeyRepository apiKeyRepository)
|
||||
{
|
||||
_apiKeyRepository = apiKeyRepository;
|
||||
}
|
||||
|
||||
public async Task RevokeAsync(ServiceAccount serviceAccount, IEnumerable<Guid> Ids)
|
||||
{
|
||||
var accessTokens = await _apiKeyRepository.GetManyByServiceAccountIdAsync(serviceAccount.Id);
|
||||
|
||||
var tokensToDelete = accessTokens.Where(at => Ids.Contains(at.Id));
|
||||
|
||||
await _apiKeyRepository.DeleteManyAsync(tokensToDelete);
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ public static class SecretsManagerCollectionExtensions
|
||||
services.AddScoped<IDeleteProjectCommand, DeleteProjectCommand>();
|
||||
services.AddScoped<ICreateServiceAccountCommand, CreateServiceAccountCommand>();
|
||||
services.AddScoped<IUpdateServiceAccountCommand, UpdateServiceAccountCommand>();
|
||||
services.AddScoped<IRevokeAccessTokensCommand, RevokeAccessTokensCommand>();
|
||||
services.AddScoped<ICreateAccessTokenCommand, CreateAccessTokenCommand>();
|
||||
services.AddScoped<ICreateAccessPoliciesCommand, CreateAccessPoliciesCommand>();
|
||||
services.AddScoped<IUpdateAccessPolicyCommand, UpdateAccessPolicyCommand>();
|
||||
|
Reference in New Issue
Block a user