繁体   English   中英

“AuthenticationBuilder”不包含“AddMicrosoftIdentityWebApp”的定义

[英]'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp'

我正在尝试将对 Graph 的支持添加到 .Net 6 应用程序中。 我以前在 .Net 5 应用程序中使用过 Graph,但我在理解如何使用 .Net 6“简化”启动程序进行连接时遇到了一些麻烦。

我已经包括了两个:

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

在 Program.cs 的 header 中,但我在以下AddMicrosoftIdentityWebApp中遇到错误:

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

我很确定我忽略了一些非常简单的东西,但我找不到它。

非常感谢任何建议。

感谢您的回复。

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

“错误 CS1061‘AuthenticationBuilder’不包含‘AddMicrosoftIdentityWebApp’的定义,并且无法找到接受类型‘AuthenticationBuilder’的第一个参数的可访问扩展方法‘AddMicrosoftIdentityWebApp’(您是否缺少 using 指令或程序集引用?)”

要解决上述错误,请尝试以下建议(如果有帮助):

  • 当您包括Microsoft.Identity.WebMicrosoft.Identity.Web.UI包时,这些库用于简化用户登录和获取 Microsoft Graph 令牌的过程。

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

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
    .AddInMemoryTokenCaches();
  • 要使用 Microsoft 标识平台终结点为您的应用程序登录用户,请使用AddMicrosoftIdentityWebApp()

  • EnableTokenAcquisitionToCallDownstreamApi()AddMicrosoftGraph添加了对调用 Microsoft Graph 的支持。

  • 否则,如果要使用生成builder ,请确保使用Microsoft.AspNetCore.Identity添加 package 并按如下方式定义生成builder

var builder = WebApplication.CreateBuilder(args);

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

active-directory-as.netcore-webapp-openidconnect-v2/README.md at master · Azure-Samples/active-directory-as.netcore-webapp-openidconnect-v2 · GitHub

配置ASP.NET核心身份| 微软文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM