title: C# Owin login results in identity=null on production system
body: <p>I've got an asp.net MVC 5 web project which is running fine on my development system. But for some reason, the login using Microsoft Owin with Facebook stops working as soon as I deploy the solution on my production system.</p>
  
  <p>The callback always retrieves ....error=access_denied as parameter and I tracked it back to the fact that owin returns null for my identity. Any clue whats going on here?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I implemented log4net in my Owin code and was able to dive deeper:</p>
  
  <pre><code>Response status code does not indicate success: 400 (Bad Request).
  Stack trace:        
  at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
  at Microsoft.Owin.Security.Facebook.FacebookAuthenticationHandler&lt;AuthenticateCoreAsync&gt;d__0.MoveNext()
  </code></pre>
  
  <p>Please not that I have already modified the facebook app to match the production urls, responses etc.</p>
  
  <pre><code>    private void ConfigureAuth(IAppBuilder app)
      {
          var cookieOptions = new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/Account/Login")
          };
  
          app.UseCookieAuthentication(cookieOptions);
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Passive
  
          app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType);
          app.UseFacebookAuthentication(new FacebookAuthenticationOptions
          {
              AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"],
              AppId = ConfigurationManager.AppSettings["FacebookAppId"],
              Provider = new FacebookAuthenticationProvider()
              {
                  OnAuthenticated = (context) =&gt;
                  {
                      context.Identity.AddClaim(new Claim(
                          IdentityUtility.ExtendedClaimTypes.IdentityProvider,
                          "Facebook"));
                      return Task.FromResult(0);
                  },
                  OnReturnEndpoint = (context) =&gt;
                  {
                      if(context.Identity == null)
                          throw new Exception(context.Response.StatusCode.ToString());
                      return Task.FromResult(0);
                  }
              }
          });
      }
  </code></pre>
  
  <p>Regards,
  Martin</p>