|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
@ -9,6 +10,8 @@ namespace Volo.Abp.Identity.AspNetCore
|
|
|
|
|
{
|
|
|
|
|
public class AbpSignInManager : SignInManager<IdentityUser>
|
|
|
|
|
{
|
|
|
|
|
protected AbpIdentityAspNetCoreOptions AbpOptions { get; }
|
|
|
|
|
|
|
|
|
|
public AbpSignInManager(
|
|
|
|
|
UserManager<IdentityUser> userManager,
|
|
|
|
|
IHttpContextAccessor contextAccessor,
|
|
|
|
@ -16,7 +19,8 @@ namespace Volo.Abp.Identity.AspNetCore
|
|
|
|
|
IOptions<IdentityOptions> optionsAccessor,
|
|
|
|
|
ILogger<SignInManager<IdentityUser>> logger,
|
|
|
|
|
IAuthenticationSchemeProvider schemes,
|
|
|
|
|
IUserConfirmation<IdentityUser> confirmation
|
|
|
|
|
IUserConfirmation<IdentityUser> confirmation,
|
|
|
|
|
IOptions<AbpIdentityAspNetCoreOptions> options
|
|
|
|
|
) : base(
|
|
|
|
|
userManager,
|
|
|
|
|
contextAccessor,
|
|
|
|
@ -26,16 +30,42 @@ namespace Volo.Abp.Identity.AspNetCore
|
|
|
|
|
schemes,
|
|
|
|
|
confirmation)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
AbpOptions = options.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task<SignInResult> PasswordSignInAsync(
|
|
|
|
|
public override async Task<SignInResult> PasswordSignInAsync(
|
|
|
|
|
string userName,
|
|
|
|
|
string password,
|
|
|
|
|
bool isPersistent,
|
|
|
|
|
bool lockoutOnFailure)
|
|
|
|
|
{
|
|
|
|
|
return base.PasswordSignInAsync(userName, password, isPersistent, lockoutOnFailure);
|
|
|
|
|
foreach (var externalLoginProviderInfo in AbpOptions.ExternalLoginProviders.Values)
|
|
|
|
|
{
|
|
|
|
|
var externalLoginProvider = (IExternalLoginProvider) Context.RequestServices
|
|
|
|
|
.GetRequiredService(externalLoginProviderInfo.Type);
|
|
|
|
|
|
|
|
|
|
if (await externalLoginProvider.TryAuthenticateAsync(userName, password))
|
|
|
|
|
{
|
|
|
|
|
var user = await UserManager.FindByNameAsync(userName);
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
user = await externalLoginProvider.CreateUserAsync(userName);
|
|
|
|
|
//TODO: TenantId, LoginProvider, Password, NormalizeNames
|
|
|
|
|
//TODO: Set default roles
|
|
|
|
|
await UserManager.CreateAsync(user);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await externalLoginProvider.UpdateUserAsync(user);
|
|
|
|
|
//TODO: LoginProvider
|
|
|
|
|
await UserManager.UpdateAsync(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await SignInOrTwoFactorAsync(user, isPersistent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await base.PasswordSignInAsync(userName, password, isPersistent, lockoutOnFailure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|