mirror of
https://github.com/bitwarden/server.git
synced 2025-06-05 18:50:35 -05:00

* Add DynamicClientStore * Formatting * Fix Debug assertion * Make Identity internals visible to its unit tests * Add installation client provider tests * Add internal client provider tests * Add DynamicClientStore tests * Fix namespaces after merge * Format * Add docs and remove TODO comments * Use preferred prefix for API keys --------- Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Bit.Core.IdentityServer;
|
|
using Bit.Core.Platform.Installations;
|
|
using Duende.IdentityServer.Models;
|
|
using IdentityModel;
|
|
|
|
namespace Bit.Identity.IdentityServer.ClientProviders;
|
|
|
|
internal class InstallationClientProvider : IClientProvider
|
|
{
|
|
private readonly IInstallationRepository _installationRepository;
|
|
|
|
public InstallationClientProvider(IInstallationRepository installationRepository)
|
|
{
|
|
_installationRepository = installationRepository;
|
|
}
|
|
|
|
public async Task<Client> GetAsync(string identifier)
|
|
{
|
|
if (!Guid.TryParse(identifier, out var installationId))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var installation = await _installationRepository.GetByIdAsync(installationId);
|
|
|
|
if (installation == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Client
|
|
{
|
|
ClientId = $"installation.{installation.Id}",
|
|
RequireClientSecret = true,
|
|
ClientSecrets = { new Secret(installation.Key.Sha256()) },
|
|
AllowedScopes = new[]
|
|
{
|
|
ApiScopes.ApiPush,
|
|
ApiScopes.ApiLicensing,
|
|
ApiScopes.ApiInstallation,
|
|
},
|
|
AllowedGrantTypes = GrantTypes.ClientCredentials,
|
|
AccessTokenLifetime = 3600 * 24,
|
|
Enabled = installation.Enabled,
|
|
Claims = new List<ClientClaim>
|
|
{
|
|
new(JwtClaimTypes.Subject, installation.Id.ToString()),
|
|
},
|
|
};
|
|
}
|
|
}
|