title: Asp.Net MVC 6 Identity 3 MongoDB External Login (Facebook)
body: <p>I'm running the RC1 of ASP.NET MVC 6 and would like to use a MongoDB Identity Provider.</p>
  
  <p>I have implemented the <a href="https://github.com/GrantMegrabyan/AspNet.Identity3.MongoDB" rel="nofollow noreferrer">provider</a> by Grant Megrabyan which is doing a great job of registering new users and allowing them to log in but I get the error: </p>
  
  <blockquote>
    <p>InvalidOperationException: No authentication handler is configured to handle the scheme: Microsoft.AspNet.Identity.External
    Microsoft.AspNet.Http.Authentication.Internal.DefaultAuthenticationManager.d__13.MoveNext()</p>
  </blockquote>
  
  <p>I had the external login previously working using EntityFramework so I'm assuming my configuration for third party auth is probably correct.</p>
  
  <p>When the user clicks login with Facebook they are redirected to the following action :</p>
  
  <pre><code>    // POST: /Account/ExternalLogin
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public IActionResult ExternalLogin(string provider, string returnUrl = null)
      {
          // Request a redirect to the external login provider.
          var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
          var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
          return new ChallengeResult(provider, properties);
      }
  </code></pre>
  
  <p>There is no exception thrown at this point however when the Facebook returns from the ChallengeResponse it sends a GET to : <a href="http://localhost:51265/signin-facebook?code=[facebook" rel="nofollow noreferrer">http://localhost:51265/signin-facebook?code=[facebook</a> user token].</p>
  
  <p>At this point ASP.NET throws the exception:</p>
  
  <p><a href="https://i.stack.imgur.com/rFzbt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rFzbt.png" alt="enter image description here"></a></p>
  
  <p>The callback url made by Facebook doesn't seem to make sense. Surely it should return to my ExternalLoginCallback action?</p>
  
  <p>It's about here that I'm out of ideas?!</p>
  
  <p>If anyone can see where I've gone wrong then I'd be a very happy guy.</p>
  
  <p>My startup.cs:</p>
  
  <pre><code>public class Startup
  {
      public Startup(IHostingEnvironment env)
      {
          // Set up configuration sources.
          var builder = new ConfigurationBuilder()
              .AddJsonFile("appsettings.json")
              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
          if (env.IsDevelopment())
          {
              // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
              builder.AddUserSecrets();
          }
  
          builder.AddEnvironmentVariables();
          Configuration = builder.Build();
      }
  
      public IConfigurationRoot Configuration { get; set; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddSingleton&lt;ApplicationDbContext&gt;();
  
          // Add framework services.
          services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
              .AddMongoStores&lt;ApplicationDbContext, ApplicationUser, IdentityRole&gt;()
              .AddDefaultTokenProviders();
  
          services.AddMvc();
  
          // Add application services.
          services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
          services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.AddConsole(Configuration.GetSection("Logging"));
          loggerFactory.AddDebug();
  
          if (env.IsDevelopment())
          {
              app.UseBrowserLink();
              app.UseDeveloperExceptionPage();
              app.UseDatabaseErrorPage();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
          }
  
          app.UseIISPlatformHandler(options =&gt; options.AuthenticationDescriptions.Clear());
  
          app.UseStaticFiles();
  
          app.UseFacebookAuthentication(options =&gt;
          {
              options.AppId = "removed";
              options.AppSecret = "removed";
          });
  
          app.UseIdentity();
  
          app.UseMvcWithDefaultRoute();
      }
  
      // Entry point for the application.
      public static void Main(string[] args) =&gt; WebApplication.Run&lt;Startup&gt;(args);
  }
  </code></pre>