AzureAD / microsoft-identity-web

Helps creating protected web apps and web APIs with Microsoft identity platform and Azure AD B2C
MIT License
682 stars 214 forks source link

Intermittent issue observed BlazorServer : AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token #2621

Open virajasawant06 opened 10 months ago

virajasawant06 commented 10 months ago

Microsoft.Identity.Web Library

Microsoft.Identity.Web.UI

Microsoft.Identity.Web version

2.16.0

Web app

Sign-in users and call web APIs

Web API

Protected web APIs call downstream web APIs

Token cache serialization

In-memory caches

Description

The application gives intermittent issue as given below:Upon restarting the application the issue is not seen,

AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token. Trace ID: 2492f1a9-288d-41c5-a2af-f571a5fe8e01 Correlation ID: c4211dbf-22b6-4fca-82d2-97a269d4db9f Timestamp: 2023-11-27 11:11:01Z

Hosting Details: Hosting is done using Azure app service. The app service plans are hosted in East Asia region with P1V2 tier. This issue is seen in all the environments except QA environment. We are actively using all environments (DEV, QA, UAT & Prod).

Application Details: Web App : Blazor Server , .net 6.0 API App : .net 6.0

Dependencies and other related packages with versions for Web App

MicrosoftTeams-image

Reproduction steps

MicrosoftTeams-image (1)

[

MicrosoftTeams-image (2)

](url)

This behavior is intermittent in occurrence.

Error message

MsalUiRequiredException: AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token. Trace ID: 15901651-997b-48a6-b621-73383b8e0800 Correlation ID: 4102fcdf-a767-46e9-888b-cd5660dbca65 Timestamp: 2023-12-21 05:13:34Z

Id Web logs

query_data (4).csv

Relevant code snippets

builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureAdWeb")
                .EnableTokenAcquisitionToCallDownstreamApi() 
                .AddInMemoryTokenCaches();

builder.Services.AddControllersWithViews()
        .AddMicrosoftIdentityUI();

builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to the default policy

Regression

No response

Expected behavior

Application should not give the intermittent issue which we are facing currently at random occurrence.

jennyf19 commented 10 months ago

@virajasawant06 Does this repro with net8.0?

virajasawant06 commented 10 months ago

@virajasawant06 Does this repro with net8.0? Not sure about it as we have not migrated code to .net8.0

westin-m commented 10 months ago

Hey @virajasawant06, we're not able to reproduce your issue. Could you please send us a basic blazorserver setup that does repro it? We will use our own test credentials. Thank you!

virajasawant06 commented 9 months ago

Hey @virajasawant06, we're not able to reproduce your issue. Could you please send us a basic blazorserver setup that does repro it? We will use our own test credentials. Thank you!

Hi, Could you please let us know the exact components/files which are required to repro this issue ? As our code base is pretty much customized we wont be able to provide the existing code. We are using blazor server app with .net 6.0 and following are the package versions

MicrosoftTeams-image (4) MicrosoftTeams-image (5)
westin-m commented 9 months ago

Hi, Could you please let us know the exact components/files which are required to repro this issue ? As our code base is pretty much customized we wont be able to provide the existing code. We are using blazor server app with .net 6.0 and following are the package versions

This is the developer app we are using. Can you help us understand what needs to change, perhaps in Startup.cs or elsewhere, to reproduce your issue?

jennyf19 commented 9 months ago

@virajasawant06 we cannot move forward without a repro from you, as we cannot repro it ourselves. Thanks.

virajasawant06 commented 9 months ago

Hi, Attaching zip file of the project which you can repro [Uploading Sample_Project.zip…]()

virajasawant06 commented 9 months ago

Sample_Project.zip

virajasawant06 commented 9 months ago

Hi @jennyf19 any update after we have sent the sample project ?