Browse Source

Handles case where users need to confirm `email` or `phone number`.

pull/21271/head
maliming 2 years ago
parent
commit
6c0fc949f9
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 8
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpErrorDescriptionConsts.cs
  2. 27
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

8
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpErrorDescriptionConsts.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.OpenIddict;
public static class AbpErrorDescriptionConsts
{
public const string RequiresTwoFactor = "RequiresTwoFactor";
public const string RequiresConfirmUser = "RequiresConfirmUser";
}

27
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

@ -127,7 +127,12 @@ public partial class TokenController
return await HandlePeriodicallyChangePasswordAsync(request, user, request.Password);
}
errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number.";
if (user.IsActive)
{
return await HandleConfirmUserAsync(request, user);
}
errorDescription = "You are not allowed to login! Your account is inactive.";
}
else
{
@ -235,7 +240,7 @@ public partial class TokenController
items: new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = nameof(SignInResult.RequiresTwoFactor)
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = AbpErrorDescriptionConsts.RequiresTwoFactor
},
parameters: new Dictionary<string, object>
{
@ -337,6 +342,24 @@ public partial class TokenController
}
}
protected virtual Task<IActionResult> HandleConfirmUserAsync(OpenIddictRequest request, IdentityUser user)
{
Logger.LogInformation($"{request.Username} needs to confirm email/phone number");
var properties = new AuthenticationProperties(
items: new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = AbpErrorDescriptionConsts.RequiresConfirmUser
},
parameters: new Dictionary<string, object>
{
["userId"] = user.Id.ToString("N"),
});
return Task.FromResult<IActionResult>(Forbid(properties, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme));
}
protected virtual async Task<IActionResult> SetSuccessResultAsync(OpenIddictRequest request, IdentityUser user)
{
// Clear the dynamic claims cache.

Loading…
Cancel
Save