Browse Source

Merge pull request #990 from colinin/fix-transaction

Fix transaction
pull/1010/head
yx lin 1 year ago
committed by GitHub
parent
commit
4accea78d8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IIdentitySessionStore.cs
  2. 74
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IdentitySessionManager.cs
  3. 10
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IdentitySessionStore.cs
  4. 2
      aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Portal/LINGYUN/Abp/IdentityServer/Portal/PortalGrantValidator.cs
  5. 6
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/AbpOpenIddictAspNetCoreSessionModule.cs
  6. 11
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/AbpOpenIddictAspNetCoreSessionOptions.cs
  7. 11
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/ProcessSignInIdentitySession.cs
  8. 15
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/RevocationIdentitySession.cs
  9. 23
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/UserinfoIdentitySession.cs
  10. 2
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Portal/LINGYUN/Abp/OpenIddict/Portal/PortalTokenExtensionGrant.cs
  11. 15
      aspnet-core/services/LY.MicroService.Applications.Single/MicroServiceApplicationsSingleModule.Configure.cs
  12. 3
      aspnet-core/services/LY.MicroService.Applications.Single/Program.cs
  13. 18
      aspnet-core/services/LY.MicroService.AuthServer/AuthServerModule.Configure.cs
  14. 3
      aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj
  15. 14
      aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs

4
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IIdentitySessionStore.cs

@ -19,6 +19,8 @@ public interface IIdentitySessionStore
/// <param name="userId">用户id</param> /// <param name="userId">用户id</param>
/// <param name="clientId">客户端id</param> /// <param name="clientId">客户端id</param>
/// <param name="ipAddresses">ip地址</param> /// <param name="ipAddresses">ip地址</param>
/// <param name="signedIn">登录时间</param>
/// <param name="lastAccessed">上次访问时间</param>
/// <param name="tenantId">租户id</param> /// <param name="tenantId">租户id</param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns>创建完成的 <seealso cref="IdentitySession"/></returns> /// <returns>创建完成的 <seealso cref="IdentitySession"/></returns>
@ -29,6 +31,8 @@ public interface IIdentitySessionStore
Guid userId, Guid userId,
string clientId, string clientId,
string ipAddresses, string ipAddresses,
DateTime signedIn,
DateTime? lastAccessed = null,
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
/// <summary> /// <summary>

74
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IdentitySessionManager.cs

@ -7,20 +7,24 @@ using System.Threading.Tasks;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.Identity.Session; namespace LINGYUN.Abp.Identity.Session;
public class IdentitySessionManager : DomainService, IIdentitySessionManager public class IdentitySessionManager : DomainService, IIdentitySessionManager
{ {
protected IDeviceInfoProvider DeviceInfoProvider { get; } protected IDeviceInfoProvider DeviceInfoProvider { get; }
protected IIdentitySessionCache IdentitySessionCache { get; }
protected IIdentitySessionStore IdentitySessionStore { get; } protected IIdentitySessionStore IdentitySessionStore { get; }
protected IdentityDynamicClaimsPrincipalContributorCache IdentityDynamicClaimsPrincipalContributorCache { get; } protected IdentityDynamicClaimsPrincipalContributorCache IdentityDynamicClaimsPrincipalContributorCache { get; }
public IdentitySessionManager( public IdentitySessionManager(
IDeviceInfoProvider deviceInfoProvider, IDeviceInfoProvider deviceInfoProvider,
IIdentitySessionCache identitySessionCache,
IIdentitySessionStore identitySessionStore, IIdentitySessionStore identitySessionStore,
IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache) IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache)
{ {
DeviceInfoProvider = deviceInfoProvider; DeviceInfoProvider = deviceInfoProvider;
IdentitySessionCache = identitySessionCache;
IdentitySessionStore = identitySessionStore; IdentitySessionStore = identitySessionStore;
IdentityDynamicClaimsPrincipalContributorCache = identityDynamicClaimsPrincipalContributorCache; IdentityDynamicClaimsPrincipalContributorCache = identityDynamicClaimsPrincipalContributorCache;
} }
@ -33,38 +37,56 @@ public class IdentitySessionManager : DomainService, IIdentitySessionManager
if (claimsPrincipal != null) if (claimsPrincipal != null)
{ {
var userId = claimsPrincipal.FindUserId(); var userId = claimsPrincipal.FindUserId();
var sessionId = claimsPrincipal.FindSessionId(); var tenantId = claimsPrincipal.FindTenantId();
if (!userId.HasValue || sessionId.IsNullOrWhiteSpace())
{ using (CurrentTenant.Change(tenantId))
return;
}
if (await IdentitySessionStore.ExistAsync(sessionId, cancellationToken))
{ {
return; var sessionId = claimsPrincipal.FindSessionId();
} if (!userId.HasValue || sessionId.IsNullOrWhiteSpace())
var deviceInfo = DeviceInfoProvider.DeviceInfo; {
return;
}
if (await IdentitySessionStore.ExistAsync(sessionId, cancellationToken))
{
return;
}
var deviceInfo = DeviceInfoProvider.DeviceInfo;
var device = deviceInfo.Device ?? IdentitySessionDevices.OAuth; var device = deviceInfo.Device ?? IdentitySessionDevices.OAuth;
var deviceDesc = deviceInfo.Description; var deviceDesc = deviceInfo.Description;
var clientIpAddress = deviceInfo.ClientIpAddress; var clientIpAddress = deviceInfo.ClientIpAddress;
var tenantId = claimsPrincipal.FindTenantId(); var clientId = claimsPrincipal.FindClientId();
var clientId = claimsPrincipal.FindClientId();
Logger.LogDebug($"Save user session for user: {userId}, session: {sessionId}");
Logger.LogDebug($"Save user session for user: {userId}, session: {sessionId}"); await IdentitySessionStore.CreateAsync(
sessionId,
device,
deviceDesc,
userId.Value,
clientId,
clientIpAddress,
Clock.Now,
Clock.Now,
tenantId,
cancellationToken);
await IdentitySessionStore.CreateAsync( Logger.LogDebug($"Remove dynamic claims cache for user: {userId}");
sessionId,
device,
deviceDesc,
userId.Value,
clientId,
clientIpAddress,
tenantId,
cancellationToken);
Logger.LogDebug($"Remove dynamic claims cache for user: {userId}"); await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(userId.Value, tenantId);
await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(userId.Value, tenantId);
await IdentitySessionCache.RefreshAsync(sessionId,
new IdentitySessionCacheItem(
device,
deviceDesc,
userId.Value,
sessionId,
clientId,
clientIpAddress,
Clock.Now,
Clock.Now));
}
} }
} }

10
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/Session/IdentitySessionStore.cs

@ -7,24 +7,20 @@ using Volo.Abp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Timing;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace LINGYUN.Abp.Identity.Session; namespace LINGYUN.Abp.Identity.Session;
public class IdentitySessionStore : IIdentitySessionStore, ITransientDependency public class IdentitySessionStore : IIdentitySessionStore, ITransientDependency
{ {
protected IClock Clock { get; }
protected ICurrentUser CurrentUser { get; } protected ICurrentUser CurrentUser { get; }
protected IGuidGenerator GuidGenerator { get; } protected IGuidGenerator GuidGenerator { get; }
protected IIdentitySessionRepository IdentitySessionRepository { get; } protected IIdentitySessionRepository IdentitySessionRepository { get; }
public IdentitySessionStore( public IdentitySessionStore(
IClock clock,
ICurrentUser currentUser, ICurrentUser currentUser,
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
IIdentitySessionRepository identitySessionRepository) IIdentitySessionRepository identitySessionRepository)
{ {
Clock = clock;
CurrentUser = currentUser; CurrentUser = currentUser;
GuidGenerator = guidGenerator; GuidGenerator = guidGenerator;
IdentitySessionRepository = identitySessionRepository; IdentitySessionRepository = identitySessionRepository;
@ -37,6 +33,8 @@ public class IdentitySessionStore : IIdentitySessionStore, ITransientDependency
Guid userId, Guid userId,
string clientId, string clientId,
string ipAddresses, string ipAddresses,
DateTime signedIn,
DateTime? lastAccessed = null,
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -52,8 +50,8 @@ public class IdentitySessionStore : IIdentitySessionStore, ITransientDependency
tenantId, tenantId,
clientId, clientId,
ipAddresses, ipAddresses,
Clock.Now, signedIn,
Clock.Now lastAccessed
); );
identitySession = await IdentitySessionRepository.InsertAsync(identitySession, cancellationToken: cancellationToken); identitySession = await IdentitySessionRepository.InsertAsync(identitySession, cancellationToken: cancellationToken);

2
aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Portal/LINGYUN/Abp/IdentityServer/Portal/PortalGrantValidator.cs

@ -89,7 +89,7 @@ public class PortalGrantValidator : IExtensionGrantValidator
Guid? tenantId = null; Guid? tenantId = null;
using (_currentTenant.Change(null)) using (_currentTenant.Change(null))
{ {
var enterprise = parameters.Get("EnterpriseId"); var enterprise = parameters.Get("enterpriseId") ?? parameters.Get("EnterpriseId");
if (enterprise.IsNullOrWhiteSpace() || !Guid.TryParse(enterprise, out var enterpriseId)) if (enterprise.IsNullOrWhiteSpace() || !Guid.TryParse(enterprise, out var enterpriseId))
{ {
// TODO: configurabled // TODO: configurabled

6
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/AbpOpenIddictAspNetCoreSessionModule.cs

@ -4,6 +4,7 @@ using LINGYUN.Abp.Identity.Session.AspNetCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict; using Volo.Abp.OpenIddict;
using static OpenIddict.Abstractions.OpenIddictConstants;
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
@ -31,5 +32,10 @@ public class AbpOpenIddictAspNetCoreSessionModule : AbpModule
options.SignInSessionEnabled = true; options.SignInSessionEnabled = true;
options.SignOutSessionEnabled = true; options.SignOutSessionEnabled = true;
}); });
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options =>
{
options.PersistentSessionGrantTypes.Add(GrantTypes.Password);
});
} }
} }

11
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/AbpOpenIddictAspNetCoreSessionOptions.cs

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
public class AbpOpenIddictAspNetCoreSessionOptions
{
public List<string> PersistentSessionGrantTypes { get; set; }
public AbpOpenIddictAspNetCoreSessionOptions()
{
PersistentSessionGrantTypes = new List<string>();
}
}

11
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/ProcessSignInIdentitySession.cs

@ -1,5 +1,5 @@
using LINGYUN.Abp.Identity.Session; using LINGYUN.Abp.Identity.Session;
using OpenIddict.Abstractions; using Microsoft.Extensions.Options;
using OpenIddict.Server; using OpenIddict.Server;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,6 +10,7 @@ namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
public class ProcessSignInIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext> public class ProcessSignInIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext>
{ {
protected IIdentitySessionManager IdentitySessionManager { get; } protected IIdentitySessionManager IdentitySessionManager { get; }
protected AbpOpenIddictAspNetCoreSessionOptions AbpOpenIddictAspNetCoreSessionOptions { get; }
public static OpenIddictServerHandlerDescriptor Descriptor { get; } public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.ProcessSignInContext>()
@ -19,14 +20,18 @@ public class ProcessSignInIdentitySession : IOpenIddictServerHandler<OpenIddictS
.SetType(OpenIddictServerHandlerType.Custom) .SetType(OpenIddictServerHandlerType.Custom)
.Build(); .Build();
public ProcessSignInIdentitySession(IIdentitySessionManager identitySessionManager) public ProcessSignInIdentitySession(
IIdentitySessionManager identitySessionManager,
IOptions<AbpOpenIddictAspNetCoreSessionOptions> abpOpenIddictAspNetCoreSessionOptions)
{ {
IdentitySessionManager = identitySessionManager; IdentitySessionManager = identitySessionManager;
AbpOpenIddictAspNetCoreSessionOptions = abpOpenIddictAspNetCoreSessionOptions.Value;
} }
public async virtual ValueTask HandleAsync(OpenIddictServerEvents.ProcessSignInContext context) public async virtual ValueTask HandleAsync(OpenIddictServerEvents.ProcessSignInContext context)
{ {
if (context.Request.IsPasswordGrantType() && context.Principal != null) if (AbpOpenIddictAspNetCoreSessionOptions.PersistentSessionGrantTypes.Contains(context.Request.GrantType) &&
context.Principal != null)
{ {
await IdentitySessionManager.SaveSessionAsync(context.Principal, context.CancellationToken); await IdentitySessionManager.SaveSessionAsync(context.Principal, context.CancellationToken);
} }

15
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/RevocationIdentitySession.cs

@ -3,6 +3,7 @@ using OpenIddict.Server;
using System; using System;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
/// <summary> /// <summary>
@ -10,6 +11,7 @@ namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
/// </summary> /// </summary>
public class RevocationIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.HandleRevocationRequestContext> public class RevocationIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.HandleRevocationRequestContext>
{ {
protected ICurrentTenant CurrentTenant { get; }
protected IIdentitySessionManager IdentitySessionManager { get; } protected IIdentitySessionManager IdentitySessionManager { get; }
public static OpenIddictServerHandlerDescriptor Descriptor { get; } public static OpenIddictServerHandlerDescriptor Descriptor { get; }
@ -20,17 +22,24 @@ public class RevocationIdentitySession : IOpenIddictServerHandler<OpenIddictServ
.SetType(OpenIddictServerHandlerType.Custom) .SetType(OpenIddictServerHandlerType.Custom)
.Build(); .Build();
public RevocationIdentitySession(IIdentitySessionManager identitySessionManager) public RevocationIdentitySession(
ICurrentTenant currentTenant,
IIdentitySessionManager identitySessionManager)
{ {
CurrentTenant = currentTenant;
IdentitySessionManager = identitySessionManager; IdentitySessionManager = identitySessionManager;
} }
public async virtual ValueTask HandleAsync(OpenIddictServerEvents.HandleRevocationRequestContext context) public async virtual ValueTask HandleAsync(OpenIddictServerEvents.HandleRevocationRequestContext context)
{ {
var tenantId = context.Principal.FindTenantId();
var sessionId = context.Principal.FindSessionId(); var sessionId = context.Principal.FindSessionId();
if (!sessionId.IsNullOrWhiteSpace()) using (CurrentTenant.Change(tenantId))
{ {
await IdentitySessionManager.RevokeSessionAsync(sessionId); if (!sessionId.IsNullOrWhiteSpace())
{
await IdentitySessionManager.RevokeSessionAsync(sessionId);
}
} }
} }
} }

23
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore.Session/LINGYUN/Abp/OpenIddict/AspNetCore/Session/UserinfoIdentitySession.cs

@ -3,6 +3,7 @@ using OpenIddict.Server;
using System; using System;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
using static OpenIddict.Abstractions.OpenIddictConstants; using static OpenIddict.Abstractions.OpenIddictConstants;
using static OpenIddict.Server.OpenIddictServerHandlers.Userinfo; using static OpenIddict.Server.OpenIddictServerHandlers.Userinfo;
@ -12,30 +13,38 @@ namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session;
/// </summary> /// </summary>
public class UserinfoIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.HandleUserinfoRequestContext> public class UserinfoIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.HandleUserinfoRequestContext>
{ {
protected ICurrentTenant CurrentTenant { get; }
protected IIdentitySessionChecker IdentitySessionChecker { get; } protected IIdentitySessionChecker IdentitySessionChecker { get; }
public static OpenIddictServerHandlerDescriptor Descriptor { get; } public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.HandleUserinfoRequestContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.HandleUserinfoRequestContext>()
.AddFilter<OpenIddictServerHandlerFilters.RequireUserinfoRequest>() .AddFilter<OpenIddictServerHandlerFilters.RequireUserinfoRequest>()
.UseScopedHandler<UserinfoIdentitySession>() .UseScopedHandler<UserinfoIdentitySession>()
.SetOrder(ValidateAccessTokenParameter.Descriptor.Order + 2_000) .SetOrder(ValidateUserinfoRequest.Descriptor.Order + 2_000)
.SetType(OpenIddictServerHandlerType.Custom) .SetType(OpenIddictServerHandlerType.Custom)
.Build(); .Build();
public UserinfoIdentitySession(IIdentitySessionChecker identitySessionChecker) public UserinfoIdentitySession(
ICurrentTenant currentTenant,
IIdentitySessionChecker identitySessionChecker)
{ {
CurrentTenant = currentTenant;
IdentitySessionChecker = identitySessionChecker; IdentitySessionChecker = identitySessionChecker;
} }
public async virtual ValueTask HandleAsync(OpenIddictServerEvents.HandleUserinfoRequestContext context) public async virtual ValueTask HandleAsync(OpenIddictServerEvents.HandleUserinfoRequestContext context)
{ {
var tenantId = context.Principal.FindTenantId();
var sessionId = context.Principal.FindSessionId(); var sessionId = context.Principal.FindSessionId();
if (sessionId.IsNullOrWhiteSpace() || using (CurrentTenant.Change(tenantId))
!await IdentitySessionChecker.ValidateSessionAsync(sessionId))
{ {
// Errors.InvalidToken ---> 401 if (sessionId.IsNullOrWhiteSpace() ||
// Errors.ExpiredToken ---> 400 !await IdentitySessionChecker.ValidateSessionAsync(sessionId))
context.Reject(Errors.InvalidToken, "The user session has expired."); {
// Errors.InvalidToken ---> 401
// Errors.ExpiredToken ---> 400
context.Reject(Errors.InvalidToken, "The user session has expired.");
}
} }
} }
} }

2
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Portal/LINGYUN/Abp/OpenIddict/Portal/PortalTokenExtensionGrant.cs

@ -52,7 +52,7 @@ public class PortalTokenExtensionGrant : ITokenExtensionGrant
{ {
LazyServiceProvider = context.HttpContext.RequestServices.GetRequiredService<IAbpLazyServiceProvider>(); LazyServiceProvider = context.HttpContext.RequestServices.GetRequiredService<IAbpLazyServiceProvider>();
var enterprise = context.Request.GetParameter("EnterpriseId")?.ToString(); var enterprise = context.Request.GetParameter("enterpriseId")?.ToString() ?? context.Request.GetParameter("EnterpriseId")?.ToString();
Guid? tenantId = null; Guid? tenantId = null;
using (CurrentTenant.Change(null)) using (CurrentTenant.Change(null))

15
aspnet-core/services/LY.MicroService.Applications.Single/MicroServiceApplicationsSingleModule.Configure.cs

@ -9,7 +9,12 @@ using LINGYUN.Abp.Identity.Session;
using LINGYUN.Abp.IdentityServer.IdentityResources; using LINGYUN.Abp.IdentityServer.IdentityResources;
using LINGYUN.Abp.Localization.CultureMap; using LINGYUN.Abp.Localization.CultureMap;
using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications;
using LINGYUN.Abp.OpenIddict.AspNetCore.Session;
using LINGYUN.Abp.OpenIddict.LinkUser;
using LINGYUN.Abp.OpenIddict.Permissions; using LINGYUN.Abp.OpenIddict.Permissions;
using LINGYUN.Abp.OpenIddict.Portal;
using LINGYUN.Abp.OpenIddict.Sms;
using LINGYUN.Abp.OpenIddict.WeChat;
using LINGYUN.Abp.Saas; using LINGYUN.Abp.Saas;
using LINGYUN.Abp.Serilog.Enrichers.Application; using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId; using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
@ -18,6 +23,7 @@ using LINGYUN.Abp.TextTemplating;
using LINGYUN.Abp.WebhooksManagement; using LINGYUN.Abp.WebhooksManagement;
using LINGYUN.Abp.WeChat.Common.Messages.Handlers; using LINGYUN.Abp.WeChat.Common.Messages.Handlers;
using LINGYUN.Abp.WeChat.Localization; using LINGYUN.Abp.WeChat.Localization;
using LINGYUN.Abp.WeChat.Work;
using LINGYUN.Abp.Wrapper; using LINGYUN.Abp.Wrapper;
using LINGYUN.Platform.Localization; using LINGYUN.Platform.Localization;
using LY.MicroService.Applications.Single.Authentication; using LY.MicroService.Applications.Single.Authentication;
@ -311,6 +317,15 @@ public partial class MicroServiceApplicationsSingleModule
options.RefreshTokenReuseLeeway = lifetime.GetValue("RefreshTokenReuseLeeway", options.RefreshTokenReuseLeeway); options.RefreshTokenReuseLeeway = lifetime.GetValue("RefreshTokenReuseLeeway", options.RefreshTokenReuseLeeway);
options.UserCodeLifetime = lifetime.GetValue("UserCode", options.UserCodeLifetime); options.UserCodeLifetime = lifetime.GetValue("UserCode", options.UserCodeLifetime);
}); });
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options =>
{
options.PersistentSessionGrantTypes.Add(SmsTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(PortalTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(LinkUserTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(WeChatTokenExtensionGrantConsts.OfficialGrantType);
options.PersistentSessionGrantTypes.Add(WeChatTokenExtensionGrantConsts.MiniProgramGrantType);
options.PersistentSessionGrantTypes.Add(AbpWeChatWorkGlobalConsts.GrantType);
});
} }
private void ConfigureEndpoints(IServiceCollection services) private void ConfigureEndpoints(IServiceCollection services)

3
aspnet-core/services/LY.MicroService.Applications.Single/Program.cs

@ -65,10 +65,11 @@ app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseCors(); app.UseCors();
app.UseAuthentication(); app.UseAuthentication();
app.UseMultiTenancy();
app.UseUnitOfWork();
app.UseAbpOpenIddictValidation(); app.UseAbpOpenIddictValidation();
app.UseAbpSession(); app.UseAbpSession();
app.UseDynamicClaims(); app.UseDynamicClaims();
app.UseMultiTenancy();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(options => app.UseSwaggerUI(options =>

18
aspnet-core/services/LY.MicroService.AuthServer/AuthServerModule.Configure.cs

@ -1,7 +1,13 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using LINGYUN.Abp.Localization.CultureMap; using LINGYUN.Abp.Localization.CultureMap;
using LINGYUN.Abp.OpenIddict.AspNetCore.Session;
using LINGYUN.Abp.OpenIddict.LinkUser;
using LINGYUN.Abp.OpenIddict.Portal;
using LINGYUN.Abp.OpenIddict.Sms;
using LINGYUN.Abp.OpenIddict.WeChat;
using LINGYUN.Abp.Serilog.Enrichers.Application; using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId; using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
using LINGYUN.Abp.WeChat.Work;
using LY.MicroService.AuthServer.Authentication; using LY.MicroService.AuthServer.Authentication;
using Medallion.Threading; using Medallion.Threading;
using Medallion.Threading.Redis; using Medallion.Threading.Redis;
@ -10,7 +16,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Caching.StackExchangeRedis;
@ -19,7 +24,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Logging;
using OpenIddict.Validation.AspNetCore;
using OpenTelemetry.Metrics; using OpenTelemetry.Metrics;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
@ -334,6 +338,16 @@ public partial class AuthServerModule
options.IsDynamicClaimsEnabled = true; options.IsDynamicClaimsEnabled = true;
options.IsRemoteRefreshEnabled = false; options.IsRemoteRefreshEnabled = false;
}); });
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options =>
{
options.PersistentSessionGrantTypes.Add(SmsTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(PortalTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(LinkUserTokenExtensionGrantConsts.GrantType);
options.PersistentSessionGrantTypes.Add(WeChatTokenExtensionGrantConsts.OfficialGrantType);
options.PersistentSessionGrantTypes.Add(WeChatTokenExtensionGrantConsts.MiniProgramGrantType);
options.PersistentSessionGrantTypes.Add(AbpWeChatWorkGlobalConsts.GrantType);
});
} }
private void ConfigureVirtualFileSystem() private void ConfigureVirtualFileSystem()
{ {

3
aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj

@ -56,8 +56,7 @@
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" /> <PackageReference Include="Volo.Abp.AspNetCore.Serilog" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" /> <PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" /> <PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" />
<PackageReference Include="Volo.Abp.OpenIddict.AspNetCore" Condition="'$(OpenIddict)'=='true'" /> <PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Condition="'$(IdentityServer4)'=='true'" />
<PackageReference Include="Volo.Abp.Autofac" /> <PackageReference Include="Volo.Abp.Autofac" />
<PackageReference Include="Volo.Abp.DistributedLocking" /> <PackageReference Include="Volo.Abp.DistributedLocking" />
<PackageReference Include="Volo.Abp.Swashbuckle" /> <PackageReference Include="Volo.Abp.Swashbuckle" />

14
aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs

@ -14,11 +14,7 @@ using Microsoft.Extensions.Hosting;
using PackageName.CompanyName.ProjectName.EntityFrameworkCore; using PackageName.CompanyName.ProjectName.EntityFrameworkCore;
using PackageName.CompanyName.ProjectName.SettingManagement; using PackageName.CompanyName.ProjectName.SettingManagement;
using Volo.Abp; using Volo.Abp;
#if OpenIddict
using Volo.Abp.OpenIddict;
#elif IdentityServer4
using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Authentication.JwtBearer;
#endif
using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
@ -54,11 +50,7 @@ namespace PackageName.CompanyName.ProjectName;
typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(AbpLocalizationManagementEntityFrameworkCoreModule), typeof(AbpLocalizationManagementEntityFrameworkCoreModule),
typeof(AbpTextTemplatingEntityFrameworkCoreModule), typeof(AbpTextTemplatingEntityFrameworkCoreModule),
#if OpenIddict
typeof(AbpOpenIddictAspNetCoreModule),
#elif IdentityServer4
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
#endif
typeof(AbpCachingStackExchangeRedisModule), typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpDistributedLockingModule), typeof(AbpDistributedLockingModule),
typeof(AbpAspNetCoreMvcWrapperModule), typeof(AbpAspNetCoreMvcWrapperModule),
@ -113,14 +105,10 @@ public partial class ProjectNameHttpApiHostModule : AbpModule
app.UseRouting(); app.UseRouting();
app.UseCors(); app.UseCors();
app.UseAuthentication(); app.UseAuthentication();
#if OpenIddict
app.UseAbpOpenIddictValidation();
#elif IdentityServer4
app.UseJwtTokenMiddleware(); app.UseJwtTokenMiddleware();
#endif app.UseMultiTenancy();
app.UseAbpSession(); app.UseAbpSession();
app.UseDynamicClaims(); app.UseDynamicClaims();
app.UseMultiTenancy();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerUI(options =>

Loading…
Cancel
Save