I have implemented Azure AD authentication in our application with code
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
})
.AddMicrosoftIdentityWebApp(options =>
{
builder.Configuration.GetSection("AzureAd").Bind(options);
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.SaveTokens = true;
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
}, null, OpenIdConnectDefaults.AuthenticationScheme, null)
.EnableTokenAcquisitionToCallDownstreamApi(options =>
{
builder.Configuration.Bind("AzureAd", options);
})
.AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraph"))
.AddInMemoryTokenCaches(options =>
{
options.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(90);
});
Now I using var accessToken = await m_tokenAcquisition.GetAccessTokenForUserAsync(Configuration["AzureAd:Scopes:0"].Split(" "),authenticationScheme: CookieAuthenticationDefaults.AuthenticationScheme);
at home controller to received logged in user token but I I am receiving below error.
IDW10503: Cannot determine the cloud Instance. The provided authentication scheme was 'Cookies'. Microsoft.Identity.Web inferred 'Cookies' as the authentication scheme. Available authentication schemes are 'Cookies,OpenIdConnect'. See https://aka.ms/id-web/authSchemes.
I have searched so many things on the Google but did not find any solutions. same solutions is working on .net 6 but once I have migrated and updated the Nuget Packages from .net 6 to .net 8 it started giving error.
I have changed the Auth Schemes and also tried so many solutions suggested by people but it did not resolved.