I saw this line of code in ASP.NET Core Identity code there:
/// <summary>
/// Find a user token if it exists.
/// </summary>
/// <param name="user">The token owner.</param>
/// <param name="loginProvider">The login provider for the token.</param>
/// <param name="name">The name of the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The user token if it exists.</returns>
protected override Task<TUserToken> FindTokenAsync(TUser user, string loginProvider, string name, CancellationToken cancellationToken)
=> UserTokens.FindAsync(new object[] { user.Id, loginProvider, name }, cancellationToken).AsTask();
I am wondering what does this line of code? it just searches for an IdentityToken with a primary key with given values of user.Id or loginProvider or name which can be the result of FindAsync documentation but is not meaningful in application context? or it is searching for a token that has fields with the given values for example generate this query:
select *
from tokens
where userId = id and loginProvider = "lp" and name = "name"
I cannot imagine why we must search for loginProvider
and name inside userId
column. If there is any reasonable goal please let me know.
FindAsync returns just one object and it just searches for one result. when it is called on a table with a simple and one column primary key with an array of objects it throws an Argument exception with this message:
Entity type 'Person' is defined with a single key property, but 2 values were passed to the 'DbSet.Find' method.
you can call the FindAsync method with array parameter just when your primary key is combined with multiple columns.
Also, I checked the AspIdentity database and found that primary key of AspNetUserTokens is defined with multiple columns: