[英]'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp'
I'm attempting to add support for Graph into a.Net 6 application.我正在尝试将对 Graph 的支持添加到 .Net 6 应用程序中。 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.
我以前在 .Net 5 应用程序中使用过 Graph,但我在理解如何使用 .Net 6“简化”启动程序进行连接时遇到了一些麻烦。
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:在 Program.cs 的 header 中,但我在以下AddMicrosoftIdentityWebApp中遇到错误:
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.非常感谢任何建议。
Thanks for the response.感谢您的回复。
As it turns out, I found that the problem was with an incorrect package being installed.事实证明,我发现问题出在安装了错误的 package。 I had included Decos.Microsoft.Indentity.Web in the packages for the solution.
我在解决方案的包中包含了 Decos.Microsoft.Indentity.Web。 I suspect that there were some collisions occurring here.
我怀疑这里发生了一些碰撞。 Once I removed the package the error no longer manifests itself.
删除 package 后,错误不再出现。
"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?)"
“错误 CS1061‘AuthenticationBuilder’不包含‘AddMicrosoftIdentityWebApp’的定义,并且无法找到接受类型‘AuthenticationBuilder’的第一个参数的可访问扩展方法‘AddMicrosoftIdentityWebApp’(您是否缺少 using 指令或程序集引用?)”
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.当您包括
Microsoft.Identity.Web
和Microsoft.Identity.Web.UI
包时,这些库用于简化用户登录和获取 Microsoft Graph 令牌的过程。
Try modifying your configured services method by removing the prefix builder
like below:尝试通过删除前缀
builder
来修改配置的服务方法,如下所示:
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.要使用 Microsoft 标识平台终结点为您的应用程序登录用户,请使用
AddMicrosoftIdentityWebApp()
。
EnableTokenAcquisitionToCallDownstreamApi()
and AddMicrosoftGraph
adds support to call Microsoft Graph. EnableTokenAcquisitionToCallDownstreamApi()
和AddMicrosoftGraph
添加了对调用 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:否则,如果要使用生成
builder
,请确保使用Microsoft.AspNetCore.Identity
添加 package 并按如下方式定义生成builder
:
var builder = WebApplication.CreateBuilder(args);
For more in detail, please refer below links:有关更多详细信息,请参阅以下链接:
active-directory-as.netcore-webapp-openidconnect-v2/README.md at master · Azure-Samples/active-directory-as.netcore-webapp-openidconnect-v2 · GitHub . active-directory-as.netcore-webapp-openidconnect-v2/README.md at master · Azure-Samples/active-directory-as.netcore-webapp-openidconnect-v2 · GitHub 。
Configure ASP.NET Core Identity | 配置ASP.NET核心身份| Microsoft Docs .
微软文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.