title: The oauth state was missing or invalid. An error was encountered while handling the remote login
body: <p>I am facing issues while implementing external login in asp.net core 2.2 (mvc) without using identity. After signing in to google it redirect back to callback url that is throwing exception as attached in the image below.</p>
  
  <blockquote>
    <p>Exception: The oauth state was missing or invalid.</p>
  </blockquote>
  
  <p>Unknown location</p>
  
  <blockquote>
    <p>Exception: An error was encountered while handling the remote login.</p>
  </blockquote>
  
  <p>Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()</p>
  
  <p>For more detailed steps that I did, <a href="https://stackoverflow.com/questions/57024576/implementing-social-login-in-asp-net-core-2-2-with-custom-db-tables-without-usin">please check here</a></p>
  
  <p><a href="https://i.stack.imgur.com/KJOqD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KJOqD.png" alt="enter image description here"></a></p>
  
  <p>Below is Startup.cs settings</p>
  
  <pre><code> public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              // This lambda determines whether user consent for non-essential cookies is needed for a given request.
              options.CheckConsentNeeded = context =&gt; true;
              options.MinimumSameSitePolicy = SameSiteMode.None;
          });
  
          services
              .AddAuthentication(options =&gt;
              {
                  options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                  options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
              })
              .AddCookie(options =&gt;
              {
                  options.Cookie.IsEssential = true;
              })
              .AddGoogle(options =&gt;
              {
                  options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                  options.ClientId = Configuration["Authentication:Google:ClientId"];
                  options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
                  options.CallbackPath = "/externallogincallback";
  
              });
  
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
      }
  </code></pre>
  
  <p>Below is my HomeController.cs settings</p>
  
  <pre><code> //Action to issue a challange to google login
      public IActionResult Google(string provider)
      {
          provider = "Google";
          //Issue a challenge to external login middleware to trigger sign in process
          //return new ChallengeResult(provider);
  
          var authenticationProperties = new AuthenticationProperties
          {
              RedirectUri = Url.Action("externallogincallback")
          };          
  
          return Challenge(authenticationProperties, "Google");
      }
  
      //Callback action to retrive signin user details
      [HttpGet("externallogincallback", Name = "externallogincallback")]
      [AllowAnonymous]
      public Task&lt;IActionResult&gt; externallogincallback(string returnUrl = null, string remoteError = null)
      {
          //Here we can retrieve the claims
          var result =  HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
  
          return null;
      }
  </code></pre>
  
  <p>In Google console setting
  Authorized redirect URIs</p>
  
  <p>For use with requests from a web server. This is the path in your application that users are redirected to after they have authenticated with Google. The path will be appended with the authorization code for access. Must have a protocol. Cannot contain URL fragments or relative paths. Cannot be a public IP address.</p>
  
  <pre><code>https://localhost:44379/externallogincallback 
  </code></pre>