title: Facebook Login using Owin Identity
body: <p>I'm trying to make a facebook login but whatever I do I keep getting an access denied error.</p>
  
  <pre><code>public partial class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              app.CreatePerOwinContext(ApplicationDbContext.Create);
              app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
              app.CreatePerOwinContext&lt;ApplicationSignInManager&gt;(ApplicationSignInManager.Create);
              app.CreatePerOwinContext&lt;ApplicationRoleManager&gt;(ApplicationRoleManager.Create);
              app.UseCookieAuthentication(new CookieAuthenticationOptions
              {
                  AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                  LoginPath = new PathString("/Login"),
                  Provider = new CookieAuthenticationProvider
                  {
                      OnValidateIdentity = SecurityStampValidator.OnValidateIdentity&lt;ApplicationUserManager, ApplicationUser&gt;(
                          validateInterval: TimeSpan.FromMinutes(30),
                          regenerateIdentity: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager))
                  }
              });
              app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
              var facebookOptions = new FacebookAuthenticationOptions();
              facebookOptions.AppId = "appId";
              facebookOptions.AppSecret = "appSecret";
              facebookOptions.Scope.Add("email");
              app.UseFacebookAuthentication(facebookOptions);
          }
      }
  </code></pre>
  
  <p>Facebook Login button</p>
  
  <pre><code>protected void FacebookLogin_Click(object sender, ImageClickEventArgs e)
      {
          var properties = new AuthenticationProperties() { RedirectUri = "Login.aspx" };
          Context.GetOwinContext().Authentication.Challenge(properties, "Facebook");
      }
  </code></pre>
  
  <p>When I press the button I get redirected to facebook and once I login in facebook I get redericted back to the login page but in de querystring I keep getting the access denied error. I'm pretty sure my login details are correct because when I press the button a second time I don't see the facebook page anymore I am immediatly redirected back to the login page.</p>
  
  <p>Why do I keep getting the access denied error. I have set everything in the facebook also using <a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on" rel="nofollow noreferrer">these instructions</a></p>
  
  <p>I sure hope anyone can help me on this.</p>