Browse Source

Support multi-tenancy

pull/4173/head
liangshiwei 6 years ago
parent
commit
6917e57881
  1. 1
      framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj
  2. 4
      framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs
  3. 18
      framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs

1
framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj

@ -17,6 +17,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="IdentityModel" Version="4.1.1" /> <PackageReference Include="IdentityModel" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.2" /> <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.2" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" /> <ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />
</ItemGroup> </ItemGroup>

4
framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs

@ -1,11 +1,13 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace Volo.Abp.IdentityModel namespace Volo.Abp.IdentityModel
{ {
[DependsOn( [DependsOn(
typeof(AbpThreadingModule) typeof(AbpThreadingModule),
typeof(AbpMultiTenancyModule)
)] )]
public class AbpIdentityModelModule : AbpModule public class AbpIdentityModelModule : AbpModule
{ {

18
framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelAuthenticationService.cs

@ -11,6 +11,7 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace Volo.Abp.IdentityModel namespace Volo.Abp.IdentityModel
@ -22,15 +23,18 @@ namespace Volo.Abp.IdentityModel
protected AbpIdentityClientOptions ClientOptions { get; } protected AbpIdentityClientOptions ClientOptions { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected IHttpClientFactory HttpClientFactory { get; } protected IHttpClientFactory HttpClientFactory { get; }
protected ICurrentTenant CurrentTenant { get; }
public IdentityModelAuthenticationService( public IdentityModelAuthenticationService(
IOptions<AbpIdentityClientOptions> options, IOptions<AbpIdentityClientOptions> options,
ICancellationTokenProvider cancellationTokenProvider, ICancellationTokenProvider cancellationTokenProvider,
IHttpClientFactory httpClientFactory) IHttpClientFactory httpClientFactory,
ICurrentTenant currentTenant)
{ {
ClientOptions = options.Value; ClientOptions = options.Value;
CancellationTokenProvider = cancellationTokenProvider; CancellationTokenProvider = cancellationTokenProvider;
HttpClientFactory = httpClientFactory; HttpClientFactory = httpClientFactory;
CurrentTenant = currentTenant;
Logger = NullLogger<IdentityModelAuthenticationService>.Instance; Logger = NullLogger<IdentityModelAuthenticationService>.Instance;
} }
@ -125,6 +129,8 @@ namespace Volo.Abp.IdentityModel
{ {
using (var httpClient = HttpClientFactory.CreateClient()) using (var httpClient = HttpClientFactory.CreateClient())
{ {
AddHeaders(httpClient);
switch (configuration.GrantType) switch (configuration.GrantType)
{ {
case OidcConstants.GrantTypes.ClientCredentials: case OidcConstants.GrantTypes.ClientCredentials:
@ -186,5 +192,15 @@ namespace Volo.Abp.IdentityModel
return Task.CompletedTask; return Task.CompletedTask;
} }
protected virtual void AddHeaders(HttpClient client)
{
//tenantId
if (CurrentTenant.Id.HasValue)
{
//TODO: Use AbpAspNetCoreMultiTenancyOptions to get the key
client.DefaultRequestHeaders.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
}
}
} }
} }

Loading…
Cancel
Save