Я реализовал внешний идентификатор Azure entra. Я могу войти в систему и выходить из системы. В файле программы. Я не могу изменить код этого. Я просто хочу позвонить в внешний API на предварительном лагке. Вот мой файл программы.
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
using System.IdentityModel.Tokens.Jwt;
var builder = WebApplication.CreateBuilder(args);
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi(
[
builder.Configuration.GetSection("DownstreamApi:Scopes:Read").Get()!,
builder.Configuration.GetSection("DownstreamApi:Scopes:Write").Get()!
]
)
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
builder.Services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();
builder.Services.AddRazorPages();// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
async Task TestMethodAsync(HttpContext context)
{
// Actual async work here
Console.WriteLine("Performing pre-logout actions");
await Task.Delay(1);
}
// This is what i have tried but not working
//builder.Services.ConfigureApplicationCookie(options =>
//{
// options.Events.OnSigningOut = async context =>
// {
// // Call your custom method here
// await TestMethodAsync(context.HttpContext);
// };
//});
Подробнее здесь: https://stackoverflow.com/questions/796 ... -is-logout
Уведомить внешние API, что пользователь выходит из системы ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение