PasswordSignInAsync of SignInManager

PasswordSignInAsync

https://github.com/dotnet/aspnetcore/blob/9da617793b3b387fd16bbc3e0ec06337569ca6ac/src/Identity/Core/src/SignInManager.cs#L336

   /// <summary>
    /// Attempts to sign in the specified <paramref name="userName"/> and <paramref name="password"/> combination
    /// as an asynchronous operation.
    /// </summary>
    /// <param name="userName">The user name to sign in.</param>
    /// <param name="password">The password to attempt to sign in with.</param>
    /// <param name="isPersistent">Flag indicating whether the sign-in cookie should persist after the browser is closed.</param>
    /// <param name="lockoutOnFailure">Flag indicating if the user account should be locked if the sign in fails.</param>
    /// <returns>The task object representing the asynchronous operation containing the <see name="SignInResult"/>
    /// for the sign-in attempt.</returns>
    public virtual async Task<SignInResult> PasswordSignInAsync(string userName, string password,
        bool isPersistent, bool lockoutOnFailure)
    {
        var user = await UserManager.FindByNameAsync(userName);
        if (user == null)
        {
            return SignInResult.Failed;
        }

        return await PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure);
    }

 

https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Extensions.Core/src/UserManager.cs#L528

 /// <summary>
    /// Finds and returns a user, if any, who has the specified user name.
    /// </summary>
    /// <param name="userName">The user name to search for.</param>
    /// <returns>
    /// The <see cref="Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userName"/> if it exists.
    /// </returns>
    public virtual async Task<TUser?> FindByNameAsync(string userName)
    {
        ThrowIfDisposed();
        ArgumentNullThrowHelper.ThrowIfNull(userName);
        userName = NormalizeName(userName);

        var user = await Store.FindByNameAsync(userName, CancellationToken).ConfigureAwait(false);

        // Need to potentially check all keys
        if (user == null && Options.Stores.ProtectPersonalData)
        {
            var keyRing = _services.GetService<ILookupProtectorKeyRing>();
            var protector = _services.GetService<ILookupProtector>();
            if (keyRing != null && protector != null)
            {
                foreach (var key in keyRing.GetAllKeyIds())
                {
                    var oldKey = protector.Protect(key, userName);
                    user = await Store.FindByNameAsync(oldKey, CancellationToken).ConfigureAwait(false);
                    if (user != null)
                    {
                        return user;
                    }
                }
            }
        }
        return user;
    }

 

Can not decode the source ocde of Microsoft.AspNetCore.Identity.dll version 6.0.16 · Issue #216 · dnSpyEx/dnSpy · GitHub

Describe the Bug

The source code decode does not work for C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\6.0.16\ref\net6.0\Microsoft.AspNetCore.Identity.dll, the corresponding nuget library is https://www.nuget.org/packages/Microsoft.AspNetCore.App.Ref/6.0.16

public class SignInManager where TUser : class
The method body for PasswordSignInAsync is throw null

 

解答:

Here is the answer from GPT-4:

The "Ref" refers to "Reference" in the filename Microsoft.AspNetCore.App.Ref.dll.

Microsoft.AspNetCore.App.Ref.dll is part of the .NET Core shared framework and includes reference assemblies, or assemblies that contain just metadata of the types in the package and no actual implementation.

These reference assemblies are used at compile time for type resolution, so the compiler can confirm that the used .NET APIs are valid and types can be resolved. At runtime, an application uses the actual runtime assemblies found in the shared framework, not these reference assemblies.


Hint: compare your dll with the one located at C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.16\Microsoft.AspNetCore.Identity.dll

 

it works when I load the assembly from the shared folder, tick the "decompile async methods" is required

 

and the code maps to https://github.com/dotnet/aspnetcore/releases/tag/v6.0.16 on commit d6f154cca3863703cf87c8b840eea9cbe20229b2
https://github.com/dotnet/aspnetcore/blob/d6f154cca3863703cf87c8b840eea9cbe20229b2/src/Identity/Core/src/SignInManager.cs#L330

 

posted @ 2023-07-03 17:17  ChuckLu  阅读(52)  评论(0编辑  收藏  举报