Документация по гибридной аутентификации и авторизации Microsoft ASP.NET Core Blazor есть несколько примеров, содержащих этот комментарий
Код: Выделить всё
private Task LoginWithExternalProviderAsync()
{
/*
Provide OpenID/MSAL code to authenticate the user. See your identity
provider's documentation for details.
Return a new ClaimsPrincipal based on a new ClaimsIdentity.
*/
var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity());
return Task.FromResult(authenticatedUser);
}
Мне просто создать минимальный API на сервере, например:
Код: Выделить всё
app.MapGet("/GetClaimsPrincipal", async (string UserName, string Password) =>{
try
{
using IServiceScope scope = app.Services.CreateScope();
IServiceProvider services = scope.ServiceProvider;
UserManager userManager = services.GetRequiredService();
SignInManager signInManager = services.GetRequiredService();
IHostEnvironmentAuthenticationStateProvider HostAuthentication = services.GetRequiredService();
AuthenticationStateProvider AuthenticationStateProvider = services.GetRequiredService();
IdentityUser? user = await userManager.FindByNameAsync(UserName);
if (user is not null)
{
bool valid = await userManager.CheckPasswordAsync(user, Password);
if (valid)
{
ClaimsPrincipal? cp = await signInManager.CreateUserPrincipalAsync(user);
return Results.Ok(cp); // Probably needs to serialized.
}
else
{
return Results.NotFound(UserName);
}
}
return Results.NotFound(UserName);
}
catch (Exception ex)
{
return Results.Problem(ex.Message);
}});
Подробнее здесь: https://stackoverflow.com/questions/791 ... or-web-app
Мобильная версия