Skip to content

Commit

Permalink
Merge pull request #21334 from abpframework/auto-merge/rel-9-0/3198
Browse files Browse the repository at this point in the history
Merge branch dev with rel-9.0
  • Loading branch information
maliming authored Nov 13, 2024
2 parents 438976c + 6c664da commit 69ddf8e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Volo.Abp.OpenIddict;

public static class AbpErrorDescriptionConsts
{
public const string RequiresTwoFactor = "RequiresTwoFactor";

public const string RequiresConfirmUser = "RequiresConfirmUser";
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
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
{
Expand Down Expand Up @@ -235,7 +240,7 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
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>
{
Expand Down Expand Up @@ -337,6 +342,26 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
}
}

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"),
["email"] = user.Email,
["phoneNumber"] = user.PhoneNumber ?? ""
});

return Task.FromResult<IActionResult>(Forbid(properties, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme));
}

protected virtual async Task<IActionResult> SetSuccessResultAsync(OpenIddictRequest request, IdentityUser user)
{
// Clear the dynamic claims cache.
Expand Down

0 comments on commit 69ddf8e

Please sign in to comment.