I'm attempting to add support for Graph into a .Net 6 application. I've previously used Graph in a .Net 5 application but I'm having some trouble understanding how to wire things up using the .Net 6 "simplified" startup.
I've included both:
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
in the header of Program.cs but I'm getting an error with AddMicrosoftIdentityWebApp in the following:
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
The error I'm getting is:
Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp' and no accessible extension method 'AddMicrosoftIdentityWebApp' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)
I'm fairly sure that I'm overlooking something pretty simple, but I cannot find it.
Any suggestions are much appreciated.
To resolve the above error, please try the below suggestions if helpful:
When you are including
Microsoft.Identity.Web,Microsoft.Identity.Web.UIpackages, these libraries are used to simplify the process of signing-in a user and acquiring tokens for Microsoft Graph.Try modifying your configured services method by removing the prefix
builderlike below:To sign-in a user for your application with Microsoft identity platform endpoint
AddMicrosoftIdentityWebApp()is used.EnableTokenAcquisitionToCallDownstreamApi()andAddMicrosoftGraphadds support to call Microsoft Graph.Otherwise, If you want to use
builder, make sure to add the package usingMicrosoft.AspNetCore.Identityand define thebuilderas below:For more in detail, please refer below links:
active-directory-aspnetcore-webapp-openidconnect-v2/README.md at master · Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2 · GitHub.
Configure ASP.NET Core Identity | Microsoft Docs.