' AuthenticationBuilder'不包含有关AddMicrosoftityWebapp'的定义。

发布于 2025-01-20 23:26:35 字数 952 浏览 0 评论 0原文

我正在尝试将对图的支持添加到.NET 6应用程序中。我以前在.NET 5应用程序中使用了Graph,但是我很难使用.NET 6“ Simplifiend”启动来了解如何将事物汇总。

我两者都包括:

using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;

program.cs的标题

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
    .AddInMemoryTokenCaches();

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷夜 2025-01-27 23:26:35

“错误cs1061'authenticationBuilder'不包含'addmicrosoftIdentitywebapp'的定义,也不包含无访问的扩展方法'addmicrosoftidentitywebapp'接受类型的'autheThicationBuilder'的第一个参数(您是否丢失了使用指令或使用指令或使用指令汇编引用?)”

要解决上述错误,请尝试以下建议,如果有用:

  • 当您包括Microsoft.Identity.web时Microsoft.Identity.web.ui软件包,这些库用于简化登录用户的过程并为Microsoft Graph获取令牌。

  • 尝试修改您的 配置的服务方法 ,通过删除前缀 builder 如下:

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
    .AddInMemoryTokenCaches();
  • 登录a使用Microsoft Identity Platform endpoint Addmicrosoftitywebapp()的用户。

  • enableTokenAcquesitionTocallDownStreamapi()addmicrosoftgraph添加支持呼叫Microsoft Graph的支持。

  • 否则,如果要使用 Builder ,请确保使用microsoft.aspnetcore.sideity 并定义 建筑商 如下:


var builder = WebApplication.CreateBuilder(args);

有关更多详细信息,请请参阅下面的链接 links:

active-directory-aspnetcore-webapp-openidConnect-v2/readme.md at master·azure-samples/active-directory-aspnetcore-webapp-openidconnect-connect-v2-v2·github

|微软文档

"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?)"

To resolve the above error, please try the below suggestions if helpful:

  • When you are including Microsoft.Identity.Web, Microsoft.Identity.Web.UI packages, 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 builder like below:

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
    .AddInMemoryTokenCaches();
  • To sign-in a user for your application with Microsoft identity platform endpoint AddMicrosoftIdentityWebApp() is used.

  • EnableTokenAcquisitionToCallDownstreamApi() and AddMicrosoftGraph adds support to call Microsoft Graph.

  • Otherwise, If you want to use builder, make sure to add the package using Microsoft.AspNetCore.Identity and define the builder as below:

var builder = WebApplication.CreateBuilder(args);

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.

迷途知返 2025-01-27 23:26:35

感谢您的回复。

事实证明,我发现问题出在安装了不正确的软件包。我已将 Decos.Microsoft.Indentity.Web 包含在解决方案的包中。我怀疑这里发生了一些碰撞。一旦我删除了包,错误就不再出现。

Thanks for the response.

As it turns out, I found that the problem was with an incorrect package being installed. I had included Decos.Microsoft.Indentity.Web in the packages for the solution. I suspect that there were some collisions occurring here. Once I removed the package the error no longer manifests itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文