I am trying to verify the email confirmation token for user but always getting INVALID TOKEN error no matter what I do.
My code is very simple
To Generate the token
EmailVerificationCode = await userManager.GenerateEmailConfirmationTokenAsync(user);
EmailVerificationHTMLFormatCode = HttpUtility.UrlEncode(EmailVerificationCode);
To Verify the Token
var result = await userManager.ConfirmEmailAsync(user, code);
I always get INVALID TOKEN error.
The things I have tried
- Checking both generated token and received token for verification by putting them into the database, they are exactly the same.
- Tried using
HttpUtility.UrlDecode(Code)
to decode the token at receiving end - Tried to just use RAW token without
HttpUtility.UrlEncode
to verify it
I also went through the following solutions
- Asp.net 2.0 Identity, ConfirmEmailAsync() getting Invalid Token
- Invalid Token. while verifying email verification code using UserManager.ConfirmEmailAsync(user.Id, code)
- AspNet.Identit 2.1.0 ConfirmEmailAsync always returns Invalid token
- Asp.NET Identity 2 giving "Invalid Token" error
No matter what I do, it is always an Invalid Token where I can clearly see the token is 100% correct.
Any idea what am I doing wrong?
Edit - If this helps, my Startup.cs
has the following Identity configurations
// For Identity
services.AddIdentity<ApplicationUser, IdentityRole>(o =>
{
// configure identity options
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();