I have the following page for external logins that is based on the default page that comes with blazor template:
@using Microsoft.AspNetCore.Authentication@using Microsoft.AspNetCore.Http.Extensions@using Microsoft.AspNetCore.Http.HttpResults@using Microsoft.AspNetCore.Identity@using Microsoft.Extensions.Primitives@using UPSVaR_Checker_web.Components.Account.Pages@using UPSVaR_Checker_web.Data@rendermode InteractiveServer@inject SignInManager<ApplicationUser> SignInManager@inject IdentityRedirectManager RedirectManager@if (externalLogins.Length == 0){<div><p> There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article about setting up this ASP.NET application to support logging in via external services</a>.</p></div>}else{<form class="form-horizontal" action="Account/PerformExternalLogin" method="post"><div><AntiforgeryToken /><input type="hidden" name="ReturnUrl" value="@ReturnUrl" /><p> @foreach (var provider in externalLogins) {<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button> }</p></div></form> @foreach (var provider in externalLogins) {<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="() => LoginWithExternalProvider(provider)">@provider.DisplayName</MudButton> }}@code { private AuthenticationScheme[] externalLogins = []; [SupplyParameterFromQuery] private string? ReturnUrl { get; set; } protected override async Task OnInitializedAsync() { externalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToArray(); } protected async Task LoginWithExternalProvider(AuthenticationScheme provider) { //This implementation is wrong, I am not even using the scheme passed from the button. The issue is I don't know what to put here var externalInfo = await SignInManager.GetExternalLoginInfoAsync(); await SignInManager.ExternalLoginSignInAsync(externalInfo.LoginProvider, externalInfo.ProviderKey, true, true); }}I am trying to use MudBlazor components to redesign the page. I have also set @rendermode InteractiveServer. On the bottom I have started trying to add buttons for the external auth providers, but I just cannot figure out how to implement the login method. The current form approach works by calling this endpoint (also part of the template):
...var accountGroup = endpoints.MapGroup("/Account"); accountGroup.MapPost("/PerformExternalLogin", ( HttpContext context, [FromServices] SignInManager<ApplicationUser> signInManager, [FromForm] string provider, [FromForm] string returnUrl) => { IEnumerable<KeyValuePair<string, StringValues>> query = [ new("ReturnUrl", returnUrl), new("Action", ExternalLogin.LoginCallbackAction)]; var redirectUrl = UriHelper.BuildRelative( context.Request.PathBase,"/Account/ExternalLogin", QueryString.Create(query)); var properties = signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); return TypedResults.Challenge(properties, [provider]); });...I know I must be missing something basic but just cannot figure out what.