Browse Source

Improved

pull/12712/head
liangshiwei 4 years ago
parent
commit
80ea30be0a
  1. 27
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderWithPasswordBase.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IExternalLoginProviderWithPassword.cs

27
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderWithPasswordBase.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Volo.Abp.Guids;
@ -8,22 +9,31 @@ namespace Volo.Abp.Identity;
public abstract class ExternalLoginProviderWithPasswordBase : ExternalLoginProviderBase, IExternalLoginProviderWithPassword
{
public bool CanObtainUserInfoWithoutPassword { get; }
public ExternalLoginProviderWithPasswordBase(
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant,
IdentityUserManager userManager,
IIdentityUserRepository identityUserRepository,
IOptions<IdentityOptions> identityOptions) :
IOptions<IdentityOptions> identityOptions,
bool canObtainUserInfoWithoutPassword = false) :
base(guidGenerator,
currentTenant,
userManager,
identityUserRepository,
identityOptions)
{
CanObtainUserInfoWithoutPassword = canObtainUserInfoWithoutPassword;
}
public async Task<IdentityUser> CreateUserAsync(string userName, string providerName, string plainPassword)
{
if (CanObtainUserInfoWithoutPassword)
{
return await CreateUserAsync(userName, providerName);
}
await IdentityOptions.SetAsync();
var externalUser = await GetUserInfoAsync(userName, plainPassword);
@ -33,13 +43,24 @@ public abstract class ExternalLoginProviderWithPasswordBase : ExternalLoginProvi
public async Task UpdateUserAsync(IdentityUser user, string providerName, string plainPassword)
{
if (CanObtainUserInfoWithoutPassword)
{
await UpdateUserAsync(user, providerName);
return;
}
await IdentityOptions.SetAsync();
var externalUser = await GetUserInfoAsync(user, plainPassword);
await UpdateUserAsync(user, externalUser, providerName);
}
protected override Task<ExternalLoginUserInfo> GetUserInfoAsync(string userName)
{
throw new NotImplementedException($"{nameof(GetUserInfoAsync)} is not implemented default. It should be overriden and implemented by the deriving class!");
}
protected abstract Task<ExternalLoginUserInfo> GetUserInfoAsync(string userName, string plainPassword);
protected virtual Task<ExternalLoginUserInfo> GetUserInfoAsync(IdentityUser user, string plainPassword)

2
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IExternalLoginProviderWithPassword.cs

@ -4,6 +4,8 @@ namespace Volo.Abp.Identity
{
public interface IExternalLoginProviderWithPassword
{
bool CanObtainUserInfoWithoutPassword { get; }
/// <summary>
/// This method is called when a user is authenticated by this source but the user does not exists yet.
/// So, the source should create the user and fill the properties.

Loading…
Cancel
Save