【发布时间】:2018-01-12 04:01:07
【问题描述】:
我有一个 ASP.NET Core 2 应用程序,现在我在从 Core 1x 迁移代码时遇到了一些问题。这里我们有一小段代码。我有这个错误,有人可以告诉我这件事是否有任何改变吗? PS:四个错误都是一样的:
对“AuthenticationTicket”类型声明的引用,它定义在 'Microsoft.AspNetCore.Authentication',但找不到。
[errors in the code][1]
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
【问题讨论】:
-
我认为我的回答不正确。似乎发生的事情是
SetResources和SetScopes方法已从 Asp.Net Core 2 中的AuthenticationTicket中删除。我试图找到它们现在的位置,或者它的新方法。 -
那太棒了,在此先感谢!
-
似乎整个想法都变了,我在GitHub 上找不到任何关于此方法的参考。我想如果您想在票证上设置声明,您可以在创建票证之前将它们设置为针对主体。 documentation 还不错,可能有一些东西。
-
再次感谢您
标签: c# .net asp.net-identity identity asp.net-core-2.0