I am having trouble combining several libraries and a load balanced environment to produce successful login functionality.
I'm working with Microsoft.AspNetCore.Identity.EntityFramework
2.0.3 and a custom SAML implementation, which uses Microsoft.AspNetCore.Identity.SignInManager.GetExternalLoginInfoAsync()
to get login information. Locally it all works fine together, even in IIS. But on a server that this is deployed to, it doesn't work. GetExternalLoginInfoAsync()
fails to authenticate, forcing the Identity system to redirect to the login page and not allow the user authentication to proceed. Though, it has intermittently worked in a load-balanced environment. Perhaps 1% of the time it works, mainly after a fresh deployment of the code. Then it goes back to not working.
This is what I see in the log when it is deployed to the load balanced server:
AuthenticationScheme: "Identity.External" was not authenticated.
This is my generic Identity startup:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
BTW, a standard ASP.Net Identity implementation works just fine in this load balanced environment. But not the implementation with GetExternalLoginInfoAsync()
.
I have looked here on SO and on MS's site, but I can't find anything that addresses this scenario.
The code I'm using is based on this project. Here is where it tries to call the method in question:
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
_logger.LogWarning("Null login info");
return RedirectToPage("./Login");
}
Locally, this does not return null, and the info
is used to login to ASP.Net Identity. On the server, it returns null.
How can I make GetExternalLoginInfoAsync()
work 100% on the server, load balanced or not, when it works just fine locally?