1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-11 12:53:50 -05:00

added installations, push scoped tokens, push api

This commit is contained in:
Kyle Spearrin
2017-08-10 14:39:11 -04:00
parent 6ff9aeac97
commit e538817eb6
17 changed files with 234 additions and 14 deletions

View File

@ -0,0 +1,49 @@
using IdentityServer4.Stores;
using System.Threading.Tasks;
using IdentityServer4.Models;
using System.Collections.Generic;
using Bit.Core.Repositories;
using System;
namespace Bit.Core.IdentityServer
{
public class ClientStore : IClientStore
{
private static IDictionary<string, Client> _apiClients = StaticClients.GetApiClients();
private readonly IInstallationRepository _installationRepository;
public ClientStore(
IInstallationRepository installationRepository)
{
_installationRepository = installationRepository;
}
public async Task<Client> FindClientByIdAsync(string clientId)
{
if(clientId.StartsWith("installation."))
{
var idParts = clientId.Split('.');
Guid id;
if(idParts.Length > 1 && Guid.TryParse(idParts[1], out id))
{
var installation = await _installationRepository.GetByIdAsync(id);
if(installation != null)
{
return new Client
{
ClientId = $"installation.{installation.Id}",
RequireClientSecret = true,
ClientSecrets = { new Secret(installation.Key.Sha256()) },
AllowedScopes = new string[] { "api.push" },
AllowedGrantTypes = GrantTypes.ClientCredentials,
AccessTokenLifetime = 3600 * 24,
Enabled = installation.Enabled
};
}
}
}
return _apiClients.ContainsKey(clientId) ? _apiClients[clientId] : null;
}
}
}