Make ASP.NET Identity 2.0 Email confirm token work for WCF and MVC

后端 未结 1 1946
时光取名叫无心
时光取名叫无心 2021-01-06 05:19

I have a service project (WCF) and MVC project which uses same database, to handle service part for Mobile and Interface part. I have to set up email confirmation on both. <

相关标签:
1条回答
  • 2021-01-06 06:04

    I found the solution. The problem was the DataProtectionProvider.

    On MVC, it was getting from:

    public static ApplicationUserManager    
        Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
        {
          var dataProtectionProvider = **options.DataProtectionProvider**;
    

    On WCF, it was from:

    var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ASP.NET");
    

    So I used same as WCF in MVC:

    var dataProtectionProvider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ASP.NET");
    

    Also, the key point is:

    • Provider name. It should be the same on both.
    • While creating the URL from WCF, we need to use HttpUtility.UrlEncode to encode the token code.

    Example:

    var code = UserManager.GenerateEmailConfirmationToken(appuser.Id);    
    var callbackUrl = string.Format("http://MVCSite/Account/ConfirmEmail?userId={0}&code={1}",    HttpUtility.UrlEncode(appuser.Id), HttpUtility.UrlEncode(code));
    

    Update

    For anyone trying to host multiple projects, you need one of these two things to be the same to still be able to use the confirmation code:

    • Application Pool
    • Machine Key

    Email Confirmation Error Invalid Token AspNet Identity

    http://gunaatita.com/Blog/How-to-Generate-Machine-Key-using-IIS/1058

    0 讨论(0)
提交回复
热议问题