GetExternalLoginInfoAsync restituisce sempre Azure AD null

GetExternalLoginInfoAsync restituisce sempre Azure AD null

La soluzione per GetExternalLoginInfoAsync restituisce sempre null Azure AD
è indicato di seguito:

GetExternalLoginInfoAsync restituisce sempre null.
Provo a integrare Azure AD in Identity.

Posso aggiungere loginProvider tramite hardcode, ad esempio?

La mia startup:

services.AddIdentity<IdentityUser, IdentityRole>()
         .AddEntityFrameworkStores<IdentityContext>()
         .AddDefaultTokenProviders();
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
         .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
services.AddControllersWithViews();
services.AddRazorPages()
         .AddMicrosoftIdentityUI();

È una breve lista, inoltre utilizzo un middleware personalizzato.

  app.UseHttpsRedirection();
  app.UseStaticFiles();
  app.UseRouting();
  app.UseAuthentication();
  app.UseAuthorization();
  app.UseEndpoints(endpoints =>
  {
    endpoints.MapControllerRoute(
      name: "default",
      pattern: "{controller=Home}/{action=Index}/{id?}");
    endpoints.MapRazorPages();
  });

Chiamo sfida facendo clic sul pulsante

[HttpGet]
public ChallengeResult ExternalSignIn()
{
  var redirectUrl = Url.Action(nameof(ExternalLoginCallback));
  var properties = _signInManager.ConfigureExternalAuthenticationProperties
                   (OpenIdConnectDefaults.AuthenticationScheme, redirectUrl);
  return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, properties);
}

Sfida chiama questo:

[HttpGet]
public async Task<IActionResult> ExternalLoginCallback()
{
  //info is null
  var info = await _signInManager.GetExternalLoginInfoAsync().ConfigureAwait(false);
  var result = await _signInManager.ExternalLoginSignInAsync(
                     info.LoginProvider, 
                     info.ProviderKey, 
                     isPersistent: false, 
                     bypassTwoFactor: false)
                     .ConfigureAwait(false);

  //other code
}      

services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme,
                options => options.SignInScheme = IdentityConstants.ExternalScheme);