(Don't be afraid of this big description, I just tried to be specific, so that it becomes easier for the answerers)
I'm building a web application using ASP.Net Core 2.1 having external login in it. But internal server error occurred when external (facebook) login is canceled and facebook redirects to the source application.
That means, you clicked on Facebook external login button and then canceled it by clicking on "Not Now" button. Facebook redirects back to your application (https://localhost:port/signin-facebook?...); and then voila -- exception.
An unhandled exception occurred while processing the request. Exception: access_denied;Description=Permissions error Unknown location
Exception: An error was encountered while handling the remote login. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()
When facebook authentication is getting prepared by the Asp.net Core system from Startup.cs class, 'https://.../signin-facebook' route will be generated automatically by the Facebook authentication provider, as described in the Microsoft docs and Github/aspnet:
- https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins?view=aspnetcore-2.1&tabs=aspnetcore2x#create-the-app-in-facebook
- https://github.com/aspnet/Security/issues/1756#issuecomment-388855389
If I hit "https://localhost:port/signin-facebook" directly without any query-string, it shows this exception: The OAuth state was missing or invalid.

But expected behavior is - it will be redirected to the default login page.
Here's the startup.cs snippet:
services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/LogIn");
services
.AddAuthentication(o => o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
});
services.AddAuthentication()
.AddFacebook(o =>
{
o.AppId = Configuration.GetValue<string>("Facebook:AppId");
o.AppSecret = Configuration.GetValue<string>("Facebook:AppSecret");
});
I configured a custom callbackpath (as descripted in microsoft doc), but same exception.
So..., what's going on? What was the problem? And what's the solution?
FYI, I'm not accessing DB from the application and using default IdentityDbContext with .UseModel() and cookie authentication using HttpContext.SigninAsync. Everything's fine when external login is completed instead of canceling.
