Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade abp 8.3 #18

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>

<PropertyGroup>
<MicrosoftPackageVersion>8.0.4</MicrosoftPackageVersion>
<AbpVersion>8.2.0</AbpVersion>
<MicrosoftPackageVersion>8.0.6</MicrosoftPackageVersion>
<AbpVersion>8.3.0</AbpVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\common.props" />

Expand Down Expand Up @@ -28,10 +28,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(MicrosoftPackageVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="$(MicrosoftPackageVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(MicrosoftPackageVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="$(MicrosoftPackageVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion host/src/Sample.HttpApi.Host/Sample.HttpApi.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="$(AbpVersion)" />
<PackageReference Include="Passingwind.SwaggerExtensions" Version="0.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 4 additions & 6 deletions host/src/Sample.HttpApi.Host/SampleHttpApiHostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -115,6 +115,8 @@ public override void ConfigureServices(ServiceConfigurationContext context)
});

Configure<AbpAntiForgeryOptions>(options => options.TokenCookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax);

Configure<AbpMvcLibsOptions>(options => options.CheckLibs = false);
}

private void ConfigureAuthentication(ServiceConfigurationContext context)
Expand Down Expand Up @@ -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<IConfiguration>();
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
Expand Down Expand Up @@ -94,7 +95,7 @@ public virtual async Task<AccountExternalLoginResultDto> 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)
{
Expand Down Expand Up @@ -148,9 +149,12 @@ protected virtual async Task<SignInResult> ExternalLoginSignInAsync(ExternalLogi
{
var user = await UserManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey);

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);
var loginEventData = new Dictionary<string, object>
{
{ "LoginProvider", loginInfo.LoginProvider },
{ "ProviderKey", loginInfo.ProviderKey },
};
await LocalEventBus.PublishAsync(new UserLoginEvent(user!.Id, UserLoginEvent.ExternalLogin, loginEventData), onUnitOfWorkComplete: true);

await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Expand Down Expand Up @@ -182,8 +186,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, object>
{
{ "CurrentUserName", currentUserName! },
{ "CurrentUserId", currentUserId! },
};

await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.ImpersonationLogout, loginEventData), onUnitOfWorkComplete: true);
}

public virtual async Task LinkLoginAsync(Guid userId)
Expand All @@ -100,15 +108,16 @@ 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);
}

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()
Expand All @@ -119,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<string, object>
{
{ "CurrentUserName", currentUserName! },
{ "CurrentUserId", currentUserId! },
};

await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.LinkLogin, loginEventData), onUnitOfWorkComplete: true);
}
else
{
Expand All @@ -137,11 +152,12 @@ 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);

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()
Expand All @@ -152,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<string, object>
{
{ "CurrentUserName", currentUserName! },
{ "CurrentUserId", currentUserId! },
};

await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.DelegationLogin, loginEventData), onUnitOfWorkComplete: true);
}

protected virtual async Task ImpersonateLoginAsync(IdentityUser user)
Expand All @@ -173,8 +195,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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<string, object>
{
{ "ProviderName", provider! },
};

await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.TwoFactorLogin, loginEventData), onUnitOfWorkComplete: true);

return GetAccountLoginResult(signInResult);
}
Expand Down Expand Up @@ -267,8 +273,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);
}

Expand All @@ -290,8 +297,6 @@ public virtual async Task<AccountVerifyTokenResultDto> 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,
Expand Down Expand Up @@ -400,8 +405,6 @@ public virtual async Task<AccountAuthenticatorRecoveryCodesResultDto> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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()
Expand Down Expand Up @@ -114,8 +113,6 @@ public virtual async Task<AccountVerifyTokenResultDto> 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,
Expand All @@ -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);
}

Expand All @@ -152,8 +149,6 @@ public virtual async Task<AccountVerifyTokenResultDto> 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,
Expand All @@ -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()
Expand All @@ -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);
}

Expand All @@ -218,8 +212,6 @@ public virtual async Task<AccountVerifyTokenResultDto> 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,
Expand All @@ -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()
Expand Down
Loading
Loading