Search code examples
c#asp.net-core

Microsoft.AspNetCore.ExternalLoginInfo class and the AuthenticationProperties property


I created a class library project with .NET 9 SDK, installed nuget package Microsoft.AspNetCore.Identity and created a class:

using System.Security.Claims;

using Microsoft.AspNetCore.Identity;

namespace ClassLibrary1;

public class Class1
{
    public Class1()
    {
        var principal = new ClaimsPrincipal();
        var externalLoginInfo = new ExternalLoginInfo(principal, "a", "b", "c");
        var pro = externalLoginInfo.AuthenticationProperties;
    }
}

I get this build error:

Class1.cs(13, 37): [CS1061] 'ExternalLoginInfo' does not contain a definition for 'AuthenticationProperties' and no accessible extension method 'AuthenticationProperties' accepting a first argument of type 'ExternalLoginInfo' could be found (are you missing a using directive or an assembly reference?)

Then I opened the assembly explorer and navigated to the installed assembly Microsoft.AspNetCore.Identity. Please see attached screenshot for the tree view of the assembly. It shows that the namespace Microsoft.AspNetCore.Identity contains a class ExternalLoginInfo. This class has no property named AuthenticationProperties.

However, this class' base class is UserLoginInfo. This base class UserLoginInfo on the other hand has two inheritors, both named ExternalLoginInfo. The first of the inheritors has no property AuthenticationProperties, and the second one has.

Where to find and how to instantiate the second inheritor with AuthenticationProperties property?

By the way, the documentation for the ExternalLoginInfo class lists the AuthenticationProperties property.

enter image description here


Solution

  • This related with the package you have installed , you should install the package Microsoft.AspNetCore.Identity.UI instead of Microsoft.AspNetCore.Identity.

    The Microsoft.AspNetCore.Identity's ExternalLoginInfo doesn't contains the AuthenticationProperties, but the Microsoft.AspNetCore.Identity.UI's package contains it.

    The Microsoft.AspNetCore.Identity.UI newest version is the 9.0.2, but the Microsoft.AspNetCore.Identity version is the 2.3.0.

    Result:

    enter image description here