'Asp.net core ExternalLoginCallback error 500

i have activated both Google and Facebook external logins, and everything works fine localhost. the problem is both of the signins return to error 500, when i try to test it in my hosted IIS site.

in google i have set in Authorized redirect URIs for example: https://localhost:44309/signin-google then i have https://mydomain.gr/signin-google http://mydomain.gr/signin-google and i still get this error. i click sign in with google, i get redirected to the https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount and when i choose an account i get error 500, and it never hits my ExternalLoginBack, which works in localhost. any idea why? do i have to publish my App in google.console first in order to make it work?.

in Startup.cs

   services.AddAuthentication()

            .AddGoogle(options =>
            {
                options.ClientId = "XXX";
                options.ClientSecret = "XXX";
            })
            .AddFacebook(options =>
            {
                options.AppId = "XXX";
                options.AppSecret = "XXX";
                options.AccessDeniedPath = new PathString("/Home/Index");//"/AccessDeniedPathInfo";
            });

and in my login controller.

 [AllowAnonymous]
    [HttpPost]
    public IActionResult ExternalGoogleLoginSubmit(string provider, string returnUrl)
    {
        provider = "Google";
        var redirectUrl = Url.Action("ExternalLoginCallback", "Home",
                                new { ReturnUrl = returnUrl });

        var properties =
            _isigninManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

        return new ChallengeResult(authenticationScheme: provider, properties);
    }
    [AllowAnonymous]
    [HttpPost]
    public IActionResult ExternalFacebookLoginSubmit(string provider, string returnUrl)
    {
        provider = "Facebook";
        var redirectUrl = Url.Action("ExternalLoginCallback", "Home",
                                new { ReturnUrl = returnUrl });

        var properties =
            _isigninManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

        return new ChallengeResult(authenticationScheme: provider, properties);
    }

    [AllowAnonymous]
    [HttpGet]
    public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
    {
        var loginInfo = await _isigninManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Index", "Home");
        }......}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source