title: External Provider Login .NET
body: <p>I had follow this tutorial for setup External Login <a href="https://code-maze.com/external-identity-provider-aspnet-core-identity/" rel="nofollow noreferrer">https://code-maze.com/external-identity-provider-aspnet-core-identity/</a>, after when I want to test login with google account, I write my email, my password. I get to fuunction ExternalLoginConfirmation where ModelState is not valid, always because Principal is null and if I do not specify returnUrl also because of that.
  Here are pictures of Debug:
  <a href="https://i.stack.imgur.com/66BWN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66BWN.png" alt="ExternalLogin Method" /></a></p>
  <p><a href="https://i.stack.imgur.com/t6WwF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t6WwF.png" alt="ExternalLoginCallback" /></a></p>
  <p>Now I'm not sure why returnUrl must be mandatory field, this can easy manage if null is to have to return to Home/Index.
  <a href="https://i.stack.imgur.com/O6Sbs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O6Sbs.png" alt="enter image description here" /></a></p>
  <p>Then when I submit I got ModelStata.IsValid as false
  <a href="https://i.stack.imgur.com/Vvilp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vvilp.png" alt="ExternalLoginConfirmation" /></a></p>
  <p>From Program.cs I have this configuration:</p>
  <pre><code>builder.Host.ConfigureContainer&lt;ContainerBuilder&gt;(containerBuilder =&gt;
  {
      containerBuilder.RegisterModule(new DefaultDomainModule());
      containerBuilder.RegisterModule(new DefaultInfrastructureModule(false));
  });
  builder.Services.AddAuthentication()
      .AddGoogle(options =&gt;
      {
          IConfigurationSection googleAuthSection = builder.Configuration.GetSection(&quot;Authentication:Google&quot;);
          options.ClientId = googleAuthSection[&quot;ClientId&quot;];
          options.ClientSecret = googleAuthSection[&quot;ClientSecret&quot;];
          options.SaveTokens = true;
  
      });
  </code></pre>
  <p>And Code from InfrastructureLayer:</p>
  <pre><code>public static void AddIdentityDbContext(this IServiceCollection services, string connectionString) =&gt;
      services.AddDbContext&lt;IdentityAppDbContext&gt;(options =&gt;
          {
              options.UseSqlServer(connectionString);
          })
          .AddIdentity&lt;IdentityUser, IdentityRole&gt;(options =&gt;
          {
              options.Password.RequireDigit = false;
              options.Password.RequireLowercase = false;
              options.Password.RequireNonAlphanumeric = false;
              options.Password.RequiredLength = 4;
              options.SignIn.RequireConfirmedEmail = true;
              options.Lockout.MaxFailedAccessAttempts = 5;
              options.User.RequireUniqueEmail = true;
          })
          .AddEntityFrameworkStores&lt;IdentityAppDbContext&gt;()
          .AddDefaultTokenProviders();
  </code></pre>