Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: rel-8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading