GetExternalLoginInfoAsync siempre devuelve Azure AD nulo

 C Programming >> Programación C >  >> Tags >> Azure
GetExternalLoginInfoAsync siempre devuelve Azure AD nulo

La solución para GetExternalLoginInfoAsync siempre devuelve Azure AD nulo
se muestra a continuación:

GetExternalLoginInfoAsync siempre devuelve nulo.
Intento integrar Azure AD en Identity.

¿Puedo agregar loginProvider por código duro, por ejemplo?

Mi inicio:

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

Es una lista corta, también uso middleware personalizado.

  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();
  });

Llamo desafío haciendo clic en el botón

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

Desafío llamar a esto:

[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);