Skip to content

Commit 81cec05

Browse files
authored
Merge pull request #9 from jxnkwlp/feature/account-identity
fix: account external callback login
2 parents f6e5d83 + 033968e commit 81cec05

File tree

15 files changed

+87
-102
lines changed

15 files changed

+87
-102
lines changed

modules/account/common.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Description>an abp module that provider account service, such as login, 2fa, account link,
77
impersonation, settings. </Description>
88
<PackageTags>abp-module</PackageTags>
9-
<Version>1.3.0</Version>
10-
<PackageVersion>1.3.0</PackageVersion>
9+
<Version>1.3.1</Version>
10+
<PackageVersion>1.3.1</PackageVersion>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
@@ -17,4 +17,4 @@
1717
</None>
1818
</ItemGroup>
1919

20-
</Project>
20+
</Project>

modules/account/src/Passingwind.Abp.Account.Application.Contracts/AccountSecurityLogPagedListRequestDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Passingwind.Abp.Account;
55

6-
public class AccountSecurityLogPagedListRequestDto : PagedAndSortedResultRequestDto
6+
public class AccountSecurityLogsPagedListRequestDto : PagedAndSortedResultRequestDto
77
{
88
public string? ApplicationName { get; set; }
99
public string? Identity { get; set; }

modules/account/src/Passingwind.Abp.Account.Application.Contracts/IAccountSecurityLogsAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ namespace Passingwind.Abp.Account;
77

88
public interface IAccountSecurityLogsAppService : IApplicationService
99
{
10-
Task<PagedResultDto<IdentitySecurityLogDto>> GetListAsync(AccountSecurityLogPagedListRequestDto input);
10+
Task<PagedResultDto<IdentitySecurityLogsDto>> GetListAsync(AccountSecurityLogsPagedListRequestDto input);
1111
}

modules/account/src/Passingwind.Abp.Account.Application/AccountExternalAppService.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class AccountExternalAppService : AccountAppBaseService, IAccountExternal
2929
{
3030
protected HttpContext? HttpContext { get; }
3131
protected IJsonSerializer JsonSerializer { get; }
32-
protected SignInManager<IdentityUser> SignInManager { get; }
32+
protected SignInManager SignInManager { get; }
3333
protected IOptions<IdentityOptions> IdentityOptions { get; }
3434
protected IdentitySecurityLogManager IdentitySecurityLogManager { get; }
3535
protected IdentityUserManager UserManager { get; }
@@ -38,7 +38,7 @@ public class AccountExternalAppService : AccountAppBaseService, IAccountExternal
3838
protected ILocalEventBus LocalEventBus { get; }
3939

4040
public AccountExternalAppService(
41-
SignInManager<IdentityUser> signInManager,
41+
SignInManager signInManager,
4242
IHttpContextAccessor httpContextAccessor,
4343
IOptions<IdentityOptions> identityOptions,
4444
IdentitySecurityLogManager identitySecurityLogManager,
@@ -102,9 +102,6 @@ public virtual async Task<AccountExternalLoginResultDto> CallbackAsync([NotNull]
102102
Logger.LogDebug("Received external login principal claims: \n{LogClaimsString}", logClaimsString);
103103
}
104104

105-
// TODO: Check Tenant ???
106-
//
107-
108105
var result = await ExternalLoginSignInAsync(loginInfo);
109106

110107
if (result.ToString() != SignInResult.Failed.ToString())
@@ -122,23 +119,18 @@ public virtual async Task<AccountExternalLoginResultDto> CallbackAsync([NotNull]
122119
throw new BusinessException(AccountErrorCodes.ExternalLoginUserNotFound);
123120
}
124121

125-
// TODO: two-factory check!
126-
// sign in
127-
await SignInManager.SignInAsync(user, false);
122+
// try login again
123+
result = await ExternalLoginSignInAsync(loginInfo);
128124

129-
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
125+
if (result.ToString() != SignInResult.Failed.ToString())
130126
{
131-
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
132-
Action = IdentitySecurityLogActionConsts.LoginSucceeded,
133-
UserName = user.Name
134-
});
135-
136-
await LocalEventBus.PublishAsync(new UserLoginEvent(user.Id, UserLoginEvent.ExternalLogin), onUnitOfWorkComplete: true);
127+
return new AccountExternalLoginResultDto(GetAccountLoginResultType(result))
128+
{
129+
RedirectUrl = input.ReturnUrl,
130+
};
131+
}
137132

138-
return new AccountExternalLoginResultDto(AccountLoginResultType.Success)
139-
{
140-
RedirectUrl = input.ReturnUrl,
141-
};
133+
throw new BusinessException(AccountErrorCodes.ExternalLoginUserNotFound);
142134
}
143135

144136
protected virtual async Task<SignInResult> ExternalLoginSignInAsync(ExternalLoginInfo loginInfo)
@@ -164,6 +156,7 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
164156
{
165157
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
166158
Action = result.ToIdentitySecurityLogAction(),
159+
UserName = user.UserName,
167160
});
168161
}
169162

modules/account/src/Passingwind.Abp.Account.Application/AccountSecurityLogsAppService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public AccountSecurityLogsAppService(IIdentitySecurityLogRepository securityLogR
1717
SecurityLogRepository = securityLogRepository;
1818
}
1919

20-
public virtual async Task<PagedResultDto<IdentitySecurityLogDto>> GetListAsync(AccountSecurityLogPagedListRequestDto input)
20+
public virtual async Task<PagedResultDto<IdentitySecurityLogsDto>> GetListAsync(AccountSecurityLogsPagedListRequestDto input)
2121
{
2222
var count = await SecurityLogRepository.GetCountAsync(
2323
startTime: input.StartTime,
@@ -42,6 +42,6 @@ public virtual async Task<PagedResultDto<IdentitySecurityLogDto>> GetListAsync(A
4242
clientId: input.ClientId,
4343
correlationId: input.CorrelationId);
4444

45-
return new PagedResultDto<IdentitySecurityLogDto>(count, ObjectMapper.Map<List<IdentitySecurityLog>, List<IdentitySecurityLogDto>>(list));
45+
return new PagedResultDto<IdentitySecurityLogsDto>(count, ObjectMapper.Map<List<IdentitySecurityLog>, List<IdentitySecurityLogsDto>>(list));
4646
}
4747
}

modules/account/src/Passingwind.Abp.Account.Application/NullAccountTwoFactorTokenSender.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,35 @@ public NullAccountTwoFactorTokenSender(ILogger<NullAccountTwoFactorTokenSender>
1717

1818
public virtual Task SendAsync(IdentityUser user, string provider, string token, CancellationToken cancellationToken = default)
1919
{
20-
Logger.LogWarning("Two-factor token not sent. Please implement '{0}' first.", typeof(IAccountTwoFactorTokenSender).FullName);
20+
Logger.NotImplement(token, typeof(IAccountTwoFactorTokenSender).FullName);
2121

2222
return Task.CompletedTask;
2323
}
2424

2525
public virtual Task SendEmailConfirmationTokenAsync(IdentityUser user, string token, CancellationToken cancellationToken = default)
2626
{
27-
Logger.LogWarning("Token not sent. Please implement '{0}' first.", typeof(IAccountTwoFactorTokenSender).FullName);
27+
Logger.NotImplement(token, typeof(IAccountTwoFactorTokenSender).FullName);
2828

2929
return Task.CompletedTask;
3030
}
3131

3232
public virtual Task SendChangePhoneNumberTokenAsync(IdentityUser user, string phoneNumber, string token, CancellationToken cancellationToken = default)
3333
{
34-
Logger.LogWarning("Token not sent. Please implement '{0}' first.", typeof(IAccountTwoFactorTokenSender).FullName);
34+
Logger.NotImplement(token, typeof(IAccountTwoFactorTokenSender).FullName);
3535

3636
return Task.CompletedTask;
3737
}
3838

3939
public virtual Task SendChangeEmailTokenAsync(IdentityUser user, string email, string token, CancellationToken cancellationToken = default)
4040
{
41-
Logger.LogWarning("Token not sent. Please implement '{0}' first.", typeof(IAccountTwoFactorTokenSender).FullName);
41+
Logger.NotImplement(token, typeof(IAccountTwoFactorTokenSender).FullName);
4242

4343
return Task.CompletedTask;
4444
}
4545
}
46+
47+
internal static partial class NullAccountTwoFactorTokenSenderLoggerMessage
48+
{
49+
[LoggerMessage("Token '{Token}' not sent. Please implement '{TypeName}' first.", Level = LogLevel.Warning)]
50+
internal static partial void NotImplement(this ILogger logger, string token, string? typeName);
51+
}

modules/account/src/Passingwind.Abp.Account.AspNetCore.IdentityClient/AccountExternalAuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public AccountExternalAuthController(IIdentityClientLoginAppService identityClie
2020

2121
[AllowAnonymous]
2222
[HttpGet("identity/{provider}/login")]
23-
public virtual async Task IdentityClientLoginAsync(string provider, string? returnUrl = null, string? returnUrlHash = null)
23+
public virtual async Task LoginAsync(string provider, string? returnUrl = null, string? returnUrlHash = null)
2424
{
2525
var redirectUrl = Url.Action("callback", values: new { returnUrl, returnUrlHash });
2626

modules/account/src/Passingwind.Abp.Account.AspNetCore.IdentityClient/IdentityClientExternalProvider.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ public override async Task LoginInfoReceivedAsync(AccountExternalCallbackLoginIn
2525
// check is debug mode
2626
var identityClient = await IdentityClientRepository.FindByProviderNameAsync(providerName);
2727

28-
// TODO check tenant
29-
//
30-
if (identityClient?.IsDebugMode == true)
28+
if (identityClient == null)
29+
{
30+
context.Handled = true;
31+
context.Result = new NotFoundResult();
32+
return;
33+
}
34+
35+
if (identityClient.IsDebugMode)
3136
{
3237
Logger.LogWarning("YOU ARE USE DEBUG MODE FOR IDENTITY PROVIDER");
3338
context.Handled = true;

modules/account/src/Passingwind.Abp.Account.HttpApi/AccountSecurityLogsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public AccountSecurityLogsController(IAccountSecurityLogsAppService service)
2020
}
2121

2222
[HttpGet]
23-
public virtual Task<PagedResultDto<IdentitySecurityLogDto>> GetListAsync([FromQuery] AccountSecurityLogPagedListRequestDto input)
23+
public virtual Task<PagedResultDto<IdentitySecurityLogsDto>> GetListAsync([FromQuery] AccountSecurityLogsPagedListRequestDto input)
2424
{
2525
return _service.GetListAsync(input);
2626
}

modules/identity/src/Passingwind.Abp.Identity.Application.Contracts/IIdentitySecurityLogAppService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Passingwind.Abp.Identity;
77

88
public interface IIdentitySecurityLogAppService : IApplicationService
99
{
10-
Task<PagedResultDto<IdentitySecurityLogDto>> GetListAsync(IdentitySecurityLogPagedListRequestDto input);
10+
Task<PagedResultDto<IdentitySecurityLogsDto>> GetListAsync(IdentitySecurityLogPagedListRequestDto input);
1111

12-
Task<IdentitySecurityLogDto> GetAsync(Guid id);
12+
Task<IdentitySecurityLogsDto> GetAsync(Guid id);
1313

1414
Task DeleteAsync(Guid id);
1515
}

0 commit comments

Comments
 (0)