1

What else do I need to program so that my web app responds to a refresh token?

I access the Azure-AD via Powershell and execute this command

Revoke-AzureADUserAllRefreshToken -ObjectId "ONJECTID".

Now, since I have 2 web apps and an already logged in user from the 1st web app calling the 2nd web app, it works out immediately that this user has to log in again with the password. But if I am already on a page in the 1st web app and just refresh the page nothing happens.

Here is my source code Program.cs:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureAd");

builder.Services.AddAuthorization(options =>
{
    options.AddPolicy("XYZ", p =>
    {
        p.RequireClaim("roles", "XYZ");
    });   
});

builder.Services.AddRazorPages().AddMvcOptions(options =>
{
    var policy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
    options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();

builder.Services.Configure<MicrosoftIdentityOptions>(options => {
    options.Events = new OpenIdConnectEvents
    {
        //When Correlation Error, back to Startpage (Browserbackbutton after login)
        OnRemoteFailure = context =>
        {
            context.Response.Redirect("/Home/Index");
            context.HandleResponse();
            return Task.CompletedTask;
        }
    };
});

//Configure the HTTP request pipeline.
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

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

app.Run();
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Atrox
  • 265
  • 1
  • 3
  • 5

0 Answers0