mirror of
https://github.com/bitwarden/server.git
synced 2025-02-01 23:31:41 +01:00
org API clients
This commit is contained in:
parent
c1c49fb67e
commit
5923b4c9bd
@ -94,6 +94,11 @@ namespace Bit.Api
|
|||||||
policy.RequireAuthenticatedUser();
|
policy.RequireAuthenticatedUser();
|
||||||
policy.RequireClaim(JwtClaimTypes.Scope, "api.licensing");
|
policy.RequireClaim(JwtClaimTypes.Scope, "api.licensing");
|
||||||
});
|
});
|
||||||
|
config.AddPolicy("Organization", policy =>
|
||||||
|
{
|
||||||
|
policy.RequireAuthenticatedUser();
|
||||||
|
policy.RequireClaim(JwtClaimTypes.Scope, "api.organization");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddScoped<AuthenticatorTokenProvider>();
|
services.AddScoped<AuthenticatorTokenProvider>();
|
||||||
|
@ -24,7 +24,8 @@ namespace Bit.Core.IdentityServer
|
|||||||
}),
|
}),
|
||||||
new ApiResource("internal", new string[] { JwtClaimTypes.Subject }),
|
new ApiResource("internal", new string[] { JwtClaimTypes.Subject }),
|
||||||
new ApiResource("api.push", new string[] { JwtClaimTypes.Subject }),
|
new ApiResource("api.push", new string[] { JwtClaimTypes.Subject }),
|
||||||
new ApiResource("api.licensing", new string[] { JwtClaimTypes.Subject })
|
new ApiResource("api.licensing", new string[] { JwtClaimTypes.Subject }),
|
||||||
|
new ApiResource("api.organization", new string[] { JwtClaimTypes.Subject })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,16 @@ namespace Bit.Core.IdentityServer
|
|||||||
private static IDictionary<string, Client> _apiClients = StaticClients.GetApiClients();
|
private static IDictionary<string, Client> _apiClients = StaticClients.GetApiClients();
|
||||||
|
|
||||||
private readonly IInstallationRepository _installationRepository;
|
private readonly IInstallationRepository _installationRepository;
|
||||||
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public ClientStore(
|
public ClientStore(
|
||||||
IInstallationRepository installationRepository,
|
IInstallationRepository installationRepository,
|
||||||
|
IOrganizationRepository organizationRepository,
|
||||||
GlobalSettings globalSettings)
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_installationRepository = installationRepository;
|
_installationRepository = installationRepository;
|
||||||
|
_organizationRepository = organizationRepository;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +75,28 @@ namespace Bit.Core.IdentityServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(clientId.StartsWith("organization."))
|
||||||
|
{
|
||||||
|
var idParts = clientId.Split('.');
|
||||||
|
if(idParts.Length > 1 && Guid.TryParse(idParts[1], out var id))
|
||||||
|
{
|
||||||
|
var org = await _organizationRepository.GetByIdAsync(id);
|
||||||
|
if(org != null)
|
||||||
|
{
|
||||||
|
return new Client
|
||||||
|
{
|
||||||
|
ClientId = $"organization.{org.Id}",
|
||||||
|
RequireClientSecret = true,
|
||||||
|
ClientSecrets = { new Secret(org.Id.ToString().Sha256()) }, // TODO: org.ApiKey
|
||||||
|
AllowedScopes = new string[] { "api.organization" },
|
||||||
|
AllowedGrantTypes = GrantTypes.ClientCredentials,
|
||||||
|
AccessTokenLifetime = 3600 * 1,
|
||||||
|
Enabled = org.Enabled, // TODO: && org.UseApi
|
||||||
|
Claims = new List<Claim> { new Claim(JwtClaimTypes.Subject, org.Id.ToString()) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return _apiClients.ContainsKey(clientId) ? _apiClients[clientId] : null;
|
return _apiClients.ContainsKey(clientId) ? _apiClients[clientId] : null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user