From 1fe6384dcca203faec7511af4f6fa7c8491727a1 Mon Sep 17 00:00:00 2001 From: jxnkwlp Date: Sun, 3 Nov 2024 15:21:47 +0800 Subject: [PATCH 1/3] feat: update abp version to 8.3 --- common.props | 6 ++--- .../Sample.EntityFrameworkCore.csproj | 8 +++---- .../Sample.HttpApi.Host.csproj | 2 +- .../SampleHttpApiHostModule.cs | 10 ++++----- .../AbpApiKeyOptions.cs | 2 +- modules/common.props | 22 +++++-------------- ...d.Abp.DictionaryManagement.TestBase.csproj | 13 +++-------- .../ClaimEqualityComparer.cs | 6 ++--- 8 files changed, 23 insertions(+), 46 deletions(-) diff --git a/common.props b/common.props index 47076e9..0417794 100644 --- a/common.props +++ b/common.props @@ -1,9 +1,9 @@  - 8.0.4 - 8.2.0 + 8.0.6 + 8.3.0 enable - \ No newline at end of file + diff --git a/host/src/Sample.EntityFrameworkCore/Sample.EntityFrameworkCore.csproj b/host/src/Sample.EntityFrameworkCore/Sample.EntityFrameworkCore.csproj index 4b3422b..0df6495 100644 --- a/host/src/Sample.EntityFrameworkCore/Sample.EntityFrameworkCore.csproj +++ b/host/src/Sample.EntityFrameworkCore/Sample.EntityFrameworkCore.csproj @@ -1,4 +1,4 @@ - + @@ -28,10 +28,8 @@ - - all - runtime; build; native; contentfiles; analyzers - + + diff --git a/host/src/Sample.HttpApi.Host/Sample.HttpApi.Host.csproj b/host/src/Sample.HttpApi.Host/Sample.HttpApi.Host.csproj index e17cca8..c72bec5 100644 --- a/host/src/Sample.HttpApi.Host/Sample.HttpApi.Host.csproj +++ b/host/src/Sample.HttpApi.Host/Sample.HttpApi.Host.csproj @@ -24,7 +24,7 @@ - + diff --git a/host/src/Sample.HttpApi.Host/SampleHttpApiHostModule.cs b/host/src/Sample.HttpApi.Host/SampleHttpApiHostModule.cs index 422b87f..2301630 100644 --- a/host/src/Sample.HttpApi.Host/SampleHttpApiHostModule.cs +++ b/host/src/Sample.HttpApi.Host/SampleHttpApiHostModule.cs @@ -4,7 +4,6 @@ using System.Linq; using Hangfire; using Hangfire.MemoryStorage; -using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; @@ -26,6 +25,7 @@ using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.AntiForgery; +using Volo.Abp.AspNetCore.Mvc.Libs; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; @@ -115,6 +115,8 @@ public override void ConfigureServices(ServiceConfigurationContext context) }); Configure(options => options.TokenCookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax); + + Configure(options => options.CheckLibs = false); } private void ConfigureAuthentication(ServiceConfigurationContext context) @@ -276,11 +278,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex app.UseSwagger(); app.UseAbpSwaggerUI(c => { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample API"); - - var configuration = context.ServiceProvider.GetRequiredService(); - c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - c.OAuthScopes("Sample"); + c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample API"); c.DisplayOperationId(); c.DisplayRequestDuration(); c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None); diff --git a/modules/api-keys/src/Passingwind.Abp.ApiKey.Domain/AbpApiKeyOptions.cs b/modules/api-keys/src/Passingwind.Abp.ApiKey.Domain/AbpApiKeyOptions.cs index e4070da..0211acf 100644 --- a/modules/api-keys/src/Passingwind.Abp.ApiKey.Domain/AbpApiKeyOptions.cs +++ b/modules/api-keys/src/Passingwind.Abp.ApiKey.Domain/AbpApiKeyOptions.cs @@ -16,6 +16,6 @@ public class AbpApiKeyOptions public AbpApiKeyOptions() { - Realm = Assembly.GetExecutingAssembly().GetName().Name; + Realm = Assembly.GetExecutingAssembly().GetName().Name!; } } diff --git a/modules/common.props b/modules/common.props index 14b9adf..0ad7c56 100644 --- a/modules/common.props +++ b/modules/common.props @@ -34,25 +34,13 @@ - - All - runtime; build; native; contentfiles; analyzers - + - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - + + + @@ -61,4 +49,4 @@ - \ No newline at end of file + diff --git a/modules/dictionary-management/test/Passingwind.Abp.DictionaryManagement.TestBase/Passingwind.Abp.DictionaryManagement.TestBase.csproj b/modules/dictionary-management/test/Passingwind.Abp.DictionaryManagement.TestBase/Passingwind.Abp.DictionaryManagement.TestBase.csproj index dd73744..b5c543e 100644 --- a/modules/dictionary-management/test/Passingwind.Abp.DictionaryManagement.TestBase/Passingwind.Abp.DictionaryManagement.TestBase.csproj +++ b/modules/dictionary-management/test/Passingwind.Abp.DictionaryManagement.TestBase/Passingwind.Abp.DictionaryManagement.TestBase.csproj @@ -10,22 +10,15 @@ - - all - runtime; build; native; contentfiles; analyzers - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - + \ No newline at end of file diff --git a/modules/identity/src/Passingwind.Abp.Identity.Domain/ClaimEqualityComparer.cs b/modules/identity/src/Passingwind.Abp.Identity.Domain/ClaimEqualityComparer.cs index 4a2c832..e41c7b2 100644 --- a/modules/identity/src/Passingwind.Abp.Identity.Domain/ClaimEqualityComparer.cs +++ b/modules/identity/src/Passingwind.Abp.Identity.Domain/ClaimEqualityComparer.cs @@ -5,9 +5,9 @@ namespace Passingwind.Abp.Identity; public class ClaimEqualityComparer : IEqualityComparer, System.Collections.IEqualityComparer { - public bool Equals(Claim x, Claim y) + public bool Equals(Claim? x, Claim? y) { - return x.Type == y.Type && x.Value == y.Value; + return x?.Type == y?.Type && x?.Value == y?.Value; } public int GetHashCode(Claim obj) @@ -15,7 +15,7 @@ public int GetHashCode(Claim obj) return obj.Type.GetHashCode() & obj.Value.GetHashCode(); } - new public bool Equals(object x, object y) + public new bool Equals(object? x, object? y) { if (x == y) { From 2a0ea49538a81ce4bdb41579dc9b2a94555aae92 Mon Sep 17 00:00:00 2001 From: jxnkwlp Date: Sun, 3 Nov 2024 15:30:58 +0800 Subject: [PATCH 2/3] fix: remove unnecessary logging --- .../AccountExternalAppService.cs | 6 +--- .../AccountImpersonationAppService.cs | 6 ---- .../AccountLoginAppService.cs | 9 ++---- .../AccountProfileAppService.cs | 28 ++++++------------- .../AccountTfaAppService.cs | 10 ------- .../AccountExternalAuthController.cs | 6 ++-- 6 files changed, 15 insertions(+), 50 deletions(-) diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs index 81357b9..481fef0 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs @@ -94,7 +94,7 @@ public virtual async Task CallbackAsync([NotNull] throw new AbpAuthorizationException("External login info is not available"); } - Logger.LogInformation("Received external login callback. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey); + Logger.LogDebug("Received external login callback. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey); if (ExternalLoginOptions.Value.LogClaims) { @@ -150,8 +150,6 @@ protected virtual async Task ExternalLoginSignInAsync(ExternalLogi await LocalEventBus.PublishAsync(new UserLoginEvent(user!.Id, UserLoginEvent.ExternalLogin), onUnitOfWorkComplete: true); - Logger.LogInformation("User use provider key '{ProviderKey}' logged in with '{LoginProvider}' provider.", loginInfo.ProviderKey, loginInfo.LoginProvider); - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityExternal, @@ -182,8 +180,6 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() loginDisplayName: loginInfo.ProviderDisplayName, generateUserName: true); - Logger.LogInformation("User with name '{UserName}' created by external login with '{LoginProvider}' provider.", user.UserName, loginInfo.LoginProvider); - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityExternal, diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs index 7c470cc..864a5a4 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs @@ -107,8 +107,6 @@ public virtual async Task LinkLoginAsync(Guid userId) if (await LinkUserManager.IsLinkedAsync(source, target, true)) { - Logger.LogInformation("User with id '{0}' has been link login by user id '{1}'", user.Id, source.UserId); - await ImpersonateLoginAsync(user); await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() @@ -140,8 +138,6 @@ public virtual async Task DelegationLoginAsync(Guid id) // Get the delegation source user var user = await UserManager.GetByIdAsync(delegation.SourceUserId); - Logger.LogInformation("User with id '{0}' has been delegation login by user id '{1}'", user.Id, CurrentUser.GetId()); - await ImpersonateLoginAsync(user); await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() @@ -173,8 +169,6 @@ protected virtual async Task ImpersonateLoginAsync(IdentityUser user) await SignInManager.SignInWithClaimsAsync(user, false, cliams); - Logger.LogInformation("User with id '{0}' has been impersonate login by user id '{1}'", user.Id, CurrentUser.Id); - await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.Identity, diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs index 615788d..a234437 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs @@ -267,8 +267,9 @@ public virtual async Task SendTfaTokenAsync(string provider) var token = await UserManager.GenerateTwoFactorTokenAsync(user, provider); - Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for provider '{provider}'.", user.Id, token, provider); - +#if DEBUG + Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for provider '{provider}'.", user.Id, token, provider); +#endif await AccountTwoFactorTokenSender.SendAsync(user, provider, token); } @@ -290,8 +291,6 @@ public virtual async Task VerifyTfaTokenAsync(strin var valid = await UserManager.VerifyTwoFactorTokenAsync(user, provider, input.Token); - Logger.LogInformation("User with id '{id}' use provider '{provider}' verify two-factor token '{token}' result: {valid}.", user.Id, input.Token, provider, valid); - return new AccountVerifyTokenResultDto { Valid = valid, @@ -400,8 +399,6 @@ public virtual async Task VerifyAuth await UserManager.GetUserIdAsync(user); - Logger.LogInformation("User with id '{id}' has enabled 2FA with an authenticator app.", user.Id); - await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor, diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountProfileAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountProfileAppService.cs index a32ffe7..cde4b2a 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountProfileAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountProfileAppService.cs @@ -66,8 +66,9 @@ public virtual async Task SendEmailConfirmAsync() var token = await UserManager.GenerateEmailConfirmationTokenAsync(user); - Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for email confirmation'.", user.Id, token); - +#if DEBUG + Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for email confirmation'.", user.Id, token); +#endif await AccountTwoFactorTokenSender.SendEmailConfirmationTokenAsync(user, token); } @@ -82,8 +83,6 @@ public virtual async Task UpdateEmailConfirmAsync(AccountVerifyTokenRequestDto i var result = await UserManager.ConfirmEmailAsync(user, input.Token); - Logger.LogInformation("User with id '{Id}' valid confirm email token result: {Valid}", user.Id, result.Succeeded); - if (result.Succeeded) { await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() @@ -114,8 +113,6 @@ public virtual async Task VerifyEmailConfirmTokenAs purpose: IdentityUserManager.ConfirmEmailTokenPurpose, token: input.Token); - Logger.LogInformation("User with id '{Id}' valid confirm email token result: {Valid}", user.Id, valid); - return new AccountVerifyTokenResultDto { Valid = valid, @@ -132,9 +129,9 @@ public virtual async Task SendChangePhoneNumberTokenAsync(AccountProfileChangePh throw new AbpAuthorizationException(); var token = await UserManager.GenerateChangePhoneNumberTokenAsync(user, input.PhoneNumber); - - Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for change phone number'.", user.Id, token); - +#if DEBUG + Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for change phone number'.", user.Id, token); +#endif await AccountTwoFactorTokenSender.SendChangePhoneNumberTokenAsync(user, input.PhoneNumber, token); } @@ -152,8 +149,6 @@ public virtual async Task VerifyChangePhoneNumberTo token: input.Token, phoneNumber: input.PhoneNumber); - Logger.LogInformation("User with id '{Id}' valid change phone number token result: {Valid}", user.Id, valid); - return new AccountVerifyTokenResultDto { Valid = valid, @@ -174,8 +169,6 @@ public virtual async Task ChangePhoneNumberAsync(AccountProfileChangePhoneNumber phoneNumber: input.PhoneNumber, token: input.Token); - Logger.LogInformation("User with id '{0}' valid change phone number token result: {1}", user.Id, result.Succeeded); - if (result.Succeeded) { await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() @@ -202,8 +195,9 @@ public virtual async Task SendChangeEmailTokenAsync(AccountProfileChangeEmailTok var token = await UserManager.GenerateChangeEmailTokenAsync(user, input.Email); - Logger.LogInformation("User with id '{id}' has been generated new token '{token}' for change email'.", user.Id, token); - +#if DEBUG + Logger.LogDebug("User with id '{id}' has been generated new token '{token}' for change email'.", user.Id, token); +#endif await AccountTwoFactorTokenSender.SendChangeEmailTokenAsync(user, input.Email, token); } @@ -218,8 +212,6 @@ public virtual async Task VerifyChangeEmailTokenAsy var valid = await UserManager.VerifyUserTokenAsync(user, IdentityOptions.Value.Tokens.ChangeEmailTokenProvider, IdentityUserManager.GetChangeEmailTokenPurpose(input.Email), input.Token); - Logger.LogInformation("User with id '{Id}' valid change email token result: {Valid}", user.Id, valid); - return new AccountVerifyTokenResultDto { Valid = valid, @@ -237,8 +229,6 @@ public virtual async Task ChangeEmailAsync(AccountProfileChangeEmailDto input) var result = await UserManager.ChangeEmailAsync(user, input.Email, input.Token); - Logger.LogInformation("User with id '{0}' valid change email token result: {1}", user.Id, result.Succeeded); - if (result.Succeeded) { await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountTfaAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountTfaAppService.cs index f62d024..65b7131 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountTfaAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountTfaAppService.cs @@ -112,8 +112,6 @@ await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() UserName = CurrentUser.UserName, }); } - - Logger.LogInformation("User with id '{id}' has two-factor disabled", user.Id); } public virtual async Task EnabledAsync() @@ -130,8 +128,6 @@ public virtual async Task EnabledAsync() { (await UserManager.SetTwoFactorEnabledAsync(user, true)).CheckErrors(); - Logger.LogInformation("User with id '{id}' has two-factor enabled", user.Id); - if (providers.Count == 0) { Logger.LogWarning("User with id '{id}' does not have any valid two-factor provider but has two-factor enabled", user.Id); @@ -205,8 +201,6 @@ public virtual async Task UpdateAuth await UserManager.GetUserIdAsync(user); - Logger.LogInformation("User with id '{id}' has enabled 2FA with an authenticator app.", user.Id); - await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor, @@ -254,8 +248,6 @@ public virtual async Task GenerateAu var codes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); - Logger.LogInformation("User with id '{id}' has generated new 2FA recovery codes.", user.Id); - await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor, @@ -299,8 +291,6 @@ public virtual async Task RemoveAuthenticatorAsync(AccountAuthenticatorCodeVerif await UserManager.RemoveAuthenticatorAsync(user); - Logger.LogInformation("User with id '{id}' has reset their authentication app key.", user.Id); - await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityTwoFactor, diff --git a/modules/account/src/Passingwind.Abp.Account.AspNetCore/AccountExternalAuthController.cs b/modules/account/src/Passingwind.Abp.Account.AspNetCore/AccountExternalAuthController.cs index 04ed48e..00069c4 100644 --- a/modules/account/src/Passingwind.Abp.Account.AspNetCore/AccountExternalAuthController.cs +++ b/modules/account/src/Passingwind.Abp.Account.AspNetCore/AccountExternalAuthController.cs @@ -94,7 +94,7 @@ public virtual async Task CallbackAsync(string returnUrl = "", st throw new AbpAuthorizationException("External login info is not available"); } - Logger.LogInformation("Received external login. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey); + Logger.LogDebug("Received external login. provider: {LoginProvider}, key: {ProviderKey}", loginInfo.LoginProvider, loginInfo.ProviderKey); if (ExternalLoginOptions.Value.LogClaims) { @@ -168,7 +168,7 @@ protected virtual async Task ExternalLoginSignInAsync(ExternalLogi bypassTwoFactor: bypassTwofactor ); - Logger.LogInformation("External login use provider key '{ProviderKey}', name '{LoginProvider}', signin result: {SignInResult}", loginInfo.ProviderKey, loginInfo.LoginProvider, signInResult); + Logger.LogDebug("External login use provider key '{ProviderKey}', name '{LoginProvider}', signin result: {SignInResult}", loginInfo.ProviderKey, loginInfo.LoginProvider, signInResult); return signInResult; } @@ -194,8 +194,6 @@ protected virtual async Task ExternalLoginSignInAsync(ExternalLogi loginDisplayName: loginInfo.ProviderDisplayName, generateUserName: true); - Logger.LogInformation("User with name '{UserName}' created by external login with '{LoginProvider}' provider.", user.UserName, loginInfo.LoginProvider); - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentitySecurityLogIdentityConsts.IdentityExternal, From 96c6934ed9f6954e7c27c38c4ac88c62958aefb7 Mon Sep 17 00:00:00 2001 From: jxnkwlp Date: Sun, 3 Nov 2024 15:43:46 +0800 Subject: [PATCH 3/3] feat: add login event data --- .../AccountExternalAppService.cs | 8 ++++- .../AccountImpersonationAppService.cs | 34 ++++++++++++++++--- .../AccountLoginAppService.cs | 10 ++++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs index 481fef0..fca3c30 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using JetBrains.Annotations; @@ -148,7 +149,12 @@ protected virtual async Task ExternalLoginSignInAsync(ExternalLogi { var user = await UserManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey); - await LocalEventBus.PublishAsync(new UserLoginEvent(user!.Id, UserLoginEvent.ExternalLogin), onUnitOfWorkComplete: true); + var loginEventData = new Dictionary + { + { "LoginProvider", loginInfo.LoginProvider }, + { "ProviderKey", loginInfo.ProviderKey }, + }; + await LocalEventBus.PublishAsync(new UserLoginEvent(user!.Id, UserLoginEvent.ExternalLogin, loginEventData), onUnitOfWorkComplete: true); await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs index 864a5a4..4b75068 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountImpersonationAppService.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Passingwind.Abp.Account.Events; using Passingwind.Abp.Identity; @@ -84,11 +83,20 @@ public virtual async Task LoginAsync(Guid userId) throw new AbpAuthorizationException(); } + var currentUserId = CurrentUser.Id; + var currentUserName = CurrentUser.Name; + IdentityUser user = await UserManager.FindByIdAsync(userId.ToString()) ?? throw new UserNotFoundException(); await ImpersonateLoginAsync(user); - await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.ImpersonationLogout), onUnitOfWorkComplete: true); + var loginEventData = new Dictionary + { + { "CurrentUserName", currentUserName! }, + { "CurrentUserId", currentUserId! }, + }; + + await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.ImpersonationLogout, loginEventData), onUnitOfWorkComplete: true); } public virtual async Task LinkLoginAsync(Guid userId) @@ -100,6 +108,9 @@ public virtual async Task LinkLoginAsync(Guid userId) var source = new IdentityLinkUserInfo(CurrentUser.GetId(), CurrentUser.TenantId); var target = new IdentityLinkUserInfo(userId, user.TenantId); + var currentUserId = CurrentUser.Id; + var currentUserName = CurrentUser.Name; + if (user.TenantId.HasValue && user.TenantId != CurrentUser.TenantId) { CurrentTenant.Change(user.TenantId.Value); @@ -117,7 +128,13 @@ await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() ExtraProperties = { { "SourceUserId", source.UserId } } }); - await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.LinkLogin), onUnitOfWorkComplete: true); + var loginEventData = new Dictionary + { + { "CurrentUserName", currentUserName! }, + { "CurrentUserId", currentUserId! }, + }; + + await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.LinkLogin, loginEventData), onUnitOfWorkComplete: true); } else { @@ -135,6 +152,9 @@ public virtual async Task DelegationLoginAsync(Guid id) throw new BusinessException(AccountErrorCodes.UserNotDelegated); } + var currentUserId = CurrentUser.Id; + var currentUserName = CurrentUser.Name; + // Get the delegation source user var user = await UserManager.GetByIdAsync(delegation.SourceUserId); @@ -148,7 +168,13 @@ await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() ExtraProperties = { { "SourceUserId", CurrentUser.GetId() } } }); - await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.DelegationLogin), onUnitOfWorkComplete: true); + var loginEventData = new Dictionary + { + { "CurrentUserName", currentUserName! }, + { "CurrentUserId", currentUserId! }, + }; + + await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.DelegationLogin, loginEventData), onUnitOfWorkComplete: true); } protected virtual async Task ImpersonateLoginAsync(IdentityUser user) diff --git a/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs b/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs index a234437..963cb4f 100644 --- a/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs +++ b/modules/account/src/Passingwind.Abp.Account.Application/AccountLoginAppService.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; @@ -145,7 +146,12 @@ await SecurityLogManager.SaveAsync(new IdentitySecurityLogContext() UserName = user.UserName, }); - await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.TwoFactorLogin), onUnitOfWorkComplete: true); + var loginEventData = new Dictionary + { + { "ProviderName", provider! }, + }; + + await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.TwoFactorLogin, loginEventData), onUnitOfWorkComplete: true); return GetAccountLoginResult(signInResult); }