【问题标题】:Reference to type 'AuthenticationTicket' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found对“AuthenticationTicket”类型的引用声称它在“Microsoft.AspNetCore.Authentication”中定义,但找不到
【发布时间】:2018-01-12 04:01:07
【问题描述】:

我有一个 ASP.NET Core 2 应用程序,现在我在从 Core 1x 迁移代码时遇到了一些问题。这里我们有一小段代码。我有这个错误,有人可以告诉我这件事是否有任何改变吗? PS:四个错误都是一样的:

对“AuthenticationTicket”类型声明的引用,它定义在 'Microsoft.AspNetCore.Authentication',但找不到。

[errors in the code][1]

enter image description here

 private async Task<AuthenticationTicket> CreateTicketAsync(OpenIdConnectRequest request, ApplicationUser user, AuthenticationProperties properties = null)
    {
        // Create a new ClaimsPrincipal containing the claims that
        // will be used to create an id_token, a token or a code.
        var principal = await _signInManager.CreateUserPrincipalAsync(user);

        // Create a new authentication ticket holding the user identity.
        var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), OpenIdConnectServerDefaults.AuthenticationScheme);
        ticket.SetResources(request.GetResources());**// ERROR IN THIS LINE**

        //if (!request.IsRefreshTokenGrantType())
        //{
        // Set the list of scopes granted to the client application.
        // Note: the offline_access scope must be granted
        // to allow OpenIddict to return a refresh token.
        ticket.SetScopes(new[] **// ERROR IN THIS LINE**
        {
                OpenIdConnectConstants.Scopes.OpenId,
                OpenIdConnectConstants.Scopes.Email,
                OpenIdConnectConstants.Scopes.Profile,
                OpenIdConnectConstants.Scopes.OfflineAccess,
                OpenIddictConstants.Scopes.Roles
            }.Intersect(request.GetScopes())); **// ERROR IN THIS LINE**
        //}
}

更新: Nuget references

【问题讨论】:

  • 我认为我的回答不正确。似乎发生的事情是 SetResourcesSetScopes 方法已从 Asp.Net Core 2 中的 AuthenticationTicket 中删除。我试图找到它们现在的位置,或者它的新方法。
  • 那太棒了,在此先感谢!
  • 似乎整个想法都变了,我在GitHub 上找不到任何关于此方法的参考。我想如果您想在票证上设置声明,您可以在创建票证之前将它们设置为针对主体。 documentation 还不错,可能有一些东西。
  • 再次感谢您

标签: c# .net asp.net-identity identity asp.net-core-2.0


【解决方案1】:

您的参考列表表明您正在混合为 ASP.NET Core 1.x 设计的包和需要 2.x 的包。由于在 2 个 ASP.NET Core 包之间引入了巨大的变化,为 1.x 构建的与身份验证相关的包可能不适用于 2.0。

尝试更新您的包以使用与 ASP.NET Core 2.0 兼容的版本。 AspNet.Security.OAuth.ValidationAspNet.Security.OpenIdConnect.PrimitivesAspNet.Security.OpenIdConnect.Server 均已更新以支持新的身份验证 API(注意:您无需引用最后两个包,因为它们是由 OpenIddict 间接引用的)。

【讨论】:

  • 你能告诉我哪些软件包适用于 asp.net core 1x,所以我可以删除它们,我是 asp.net core 的新手,它真的很复杂。顺便说一句,谢谢你的回答
  • @dayanrr91 你可以从我提到的 3 个包开始。要了解是否为 1.x 或 2.x 制作了其他包,您可以在 nuget.org 上键入它们的名称,并查看它们是否引用 1.x 或 2.x ASP.NET Core 包。
  • 非常感谢老兄,我没有注意到我指向的是 Core 1x 的包。我刚刚升级了它们,错误就消失了。
猜你喜欢
  • 1970-01-01
  • 2018-11-23
  • 2018-09-12
  • 2018-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-07
  • 2012-08-19
相关资源
最近更新 更多