I am successfully using Azure AD and Office365 as a login provider in AspNet-Core Identity by using Microsoft.AspnetCore.Authentication.OpenIdConnect and calling
AddRemoteScheme<OpenIdConnectOptions, OpenIdConnectHandler>("AzureAD","Office 365",_=> { })
I then add a PostConfigureOptions handler for the OpenIdConnectOptions to set it up to work with Azure. This adds a Login with Office 365 button to the login page and is working, but there must be an easier way.
I was curious to see if Microsoft.Identity.Web could be used instead, but am unable to get it to work quite right in my test.
Using the Aspnet-Core templates for dotnet 6 in VS 2022 and selecting individual accounts for authentication you are scaffolded a project with AspNet-Core Identity configured to use an IdentityDbContext with local accounts.
When running the app and logging in, you see an empty list of external authentication providers and a link to Microsoft documentation on adding external authentication providers here:
To test the Microsoft.Identity.Web package, I am calling:
builder.Services.AddAuthentication().AddMicrosoftIdentityWebApp(config.GetSection("AzureAD"))
in Programs.cs
This works to add the authentication provider and I now get an "OpenIdConnect" button under "Use another service to log in". Clicking it results in a failure "Error loading external login information."
When trying to login by clicking the button, I receive "Error loading external login information.". Line 107 in ExternalLogin.cshtml.cs from Microsoft's Identity UI is always null:
var info = await _signInManager.GetExternalLoginInfoAsync();
Is it possible to provide the right arguments to .AddMicrosoftIdentityWebApp() such that it works with AspNet-Core Identity as an external authentication provider using minimal code and configuration?