UserManager VerifyUserTokenAsync Always False
I am generating usertoken for example
public async Task GenerateCode()
{
var code = await UserManager.GenerateUserTokenAsync("heymega", new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744"));
}
Then I pass the same token to another activity via a separate request
public async Task ValidateCode(string code)
{
var valid = await UserManager.VerifyUserTokenAsync(new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744"), "heymega", code); //Returns False
}
However, the answer from the method is VerifyUserTokenAsync
always wrong.
If I had to generate the code and check within the same action
public async Task GenerateCode()
{
var code = await UserManager.GenerateUserTokenAsync("heymega", new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744"));
var valid = await UserManager.VerifyUserTokenAsync(new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744"), "heymega", code); //Returns True
}
It returns true.
Why can't the Verify method validate the code in a separate request? Am I missing something?
+3
source to share
3 answers
Once burned 2 days on this issue, here's another reason why this might happen to you.
In your Startup.cs service - ConfigureServices (IServiceCollection services) make sure that:
services.AddAuthentication
Appears BEFORE
services.AddIdentity
Otherwise, calls to VerifyUserTokenAsync will always return false
0
source to share