Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserStore does not update tokens when SetTokenAsync() is used #104

Open
martincostello opened this issue Mar 19, 2023 · 0 comments
Open
Assignees
Milestone

Comments

@martincostello
Copy link
Contributor

By default, the base implementation of UserStoreBase<T> in ASP.NET Core Identity, which the UserStore<T...> classes derive from, does not write to the underlying data store by default if a token being set already exists in the store as it assumes change-tracking is used.

Depending on the outcome of dotnet/aspnetcore#47306, to prevent other consumers of this library from falling into the same pit of failure, it would be worth considering changing the base implementation in this library to do the following instead:

public virtual async Task SetTokenAsync(TUser user, string loginProvider, string name, string? value, CancellationToken cancellationToken)
{
    cancellationToken.ThrowIfCancellationRequested();
    ThrowIfDisposed();

    ArgumentNullException.ThrowIfNull(user);

    var token = await FindTokenAsync(user, loginProvider, name, cancellationToken);

    if (token is null)
    {
        token = CreateUserToken(user, loginProvider, name, value);
    }

    await AddUserTokenAsync(token);
}
@dlmelendez dlmelendez self-assigned this Mar 20, 2023
@dlmelendez dlmelendez modified the milestones: v8.0, v7.0, 7.1 Nov 6, 2023
dlmelendez added a commit that referenced this issue Nov 6, 2023
@dlmelendez dlmelendez mentioned this issue Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants