Asp.NET Identity 2 giving “Invalid Token” error

前端 未结 21 2011
情话喂你
情话喂你 2020-11-27 03:04

I\'m using Asp.Net-Identity-2 and I\'m trying to verify email verification code using the below method. But I am getting an \"Invalid Token\"

21条回答
  •  时光说笑
    2020-11-27 03:44

    Related to chenny's 3. Different instances of token providers .

    In my case I was passing IDataProtectionProvider.Create a new guid every time it got called, which prevented existing codes from being recognized in subsequent web api calls (each request creates its own user manager).

    Making the string static solved it for me.

    private static string m_tokenProviderId = "MyApp_" + Guid.NewGuid().ToString();
    ...
    manager.UserTokenProvider =
      new DataProtectorTokenProvider(
      dataProtectionProvider.Create(new string[1] { m_tokenProviderId } ))
      {
          TokenLifespan = TimeSpan.FromMinutes(accessTokenLifespan)
      };
    

提交回复
热议问题