The data protection operation was unsuccessful on Azure using OWIN / Katana

前端 未结 7 1035
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 19:37

I\'m trying to implement password reset on an OWIN/Katana based ASP.NET MVC website running in Azure.

It works fine when run locally but fails in production.

7条回答
  •  渐次进展
    2020-12-08 20:28

    I found a solution. I'm not exactly sure if all steps are necessary to it work, but now my app works perfectly:

    1.- Update your web.config to support securityTokenHandlers

    in the configSections node. And

      
        
    
        
          
        
      
    
    
    

    as a regular node. 2.- In your Startup.Auth.cs file, update your ConfigureAuth(IAppBuilder app) like this:

    public void ConfigureAuth(IAppBuilder app)
            {
    
                UserManagerFactory = () =>
                {
                    var userManager = new UserManager(new UserStore(new SIAgroUserDbContext()));
    
                    IDataProtectionProvider provider = app.GetDataProtectionProvider();
    
                    //userManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider(provider.Create("PasswordReset") );
                    if (provider != null)
                    {
                        userManager.UserTokenProvider = new DataProtectorTokenProvider(provider.Create("PasswordReset"));
                    }
    
                    return userManager;
                };
    
                OAuthOptions = new OAuthAuthorizationServerOptions
                {
                    TokenEndpointPath = new PathString("/Token"),
                    Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
                    AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                    AllowInsecureHttp = true
                };
                // Enable the application to use a cookie to store information for the signed in user
                // and to use a cookie to temporarily store information about a user logging in with a third party login provider
                app.UseCookieAuthentication(new CookieAuthenticationOptions());
                app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    
                // Enable the application to use bearer tokens to authenticate users
                app.UseOAuthBearerTokens(OAuthOptions);
    
                // Uncomment the following lines to enable logging in with third party login providers
                //app.UseMicrosoftAccountAuthentication(
                //    clientId: "",
                //    clientSecret: "");
    
                //app.UseTwitterAuthentication(
                //    consumerKey: "",
                //    consumerSecret: "");
    
                //app.UseFacebookAuthentication(
                //    appId: "",
                //    appSecret: "");
    
                //app.UseGoogleAuthentication();
    
    
    
            }
    

    3.- Clean up the constructor of your Startup class like this:

    static Startup()
    {
       PublicClientId = "self";
    }
    

    That worked for me :) I hope it works for you too

提交回复
热议问题