Search code examples
c#.netasp.net-identityidentityasp.net-core-2.0

Reference to type 'AuthenticationTicket' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found


I have an ASP.NET Core 2 application, right now I am having some issues with migrating the code that I have from Core 1x. Here we have a small piece of code. I am having this errors, can anybody tell me if anything changed in this matter please? PS: All four errors are the same:

Reference to type 'AuthenticationTicket' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found.

[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**
        //}
}

UPDATE: Nuget references


Solution

  • Your references list indicates that you're mixing packages designed for ASP.NET Core 1.x and packages that require 2.x. Since massive changes have been introduced between the 2 ASP.NET Core packages, authentication-related packages built for 1.x won't likely work with 2.0.

    Try to update your packages to use ASP.NET Core 2.0-compatible versions. AspNet.Security.OAuth.Validation, AspNet.Security.OpenIdConnect.Primitives, AspNet.Security.OpenIdConnect.Server have all been updated to support the new authentication APIs (note: you don't need to reference the last 2 packages as they are indirectly referenced by OpenIddict).