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

UserManager.AddToRolesAsync() and RemoveFromRolesAsync() fail on any conflict #55772

Open
1 task done
CollectorOfBolts opened this issue May 17, 2024 · 0 comments
Open
1 task done
Labels
area-identity Includes: Identity and providers enhancement This issue represents an ask for new feature or an enhancement to an existing one
Milestone

Comments

@CollectorOfBolts
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When adding multiple roles or generally updating a user's roles, UserManager.AddToRolesAsync() will fail upon finding that the user already has one of the given roles. Similary, UserManager.RemoveFromRolesAsync() will fail if the user does not have any of the given roles to be removed.

Expected Behavior

UserManager.AddToRolesAsync() should add all given roles to the user and simply skip any that the user already has and UserManager.RemoveFromRolesAsync() should remove all given roles from the user and simply skip any that the user does not have.

Steps To Reproduce

// with userManager coming from dependency injection and user being the IdentityUser object for some user
string role1 = "Role1";
await userManager.AddToRoleAsync(user, role1); // success
string[] roleGroup = [ "Role1", "Role2", "Role3" ];
IdentityResult result = await userManager.AddToRolesAsync(user, roleGroup);
if (!result.Succeeded) { throw new Exception("Failed to add roles"); } // will always throw here

Exceptions (if any)

No response

.NET Version

8.0.101

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-identity Includes: Identity and providers label May 17, 2024
@MackinnonBuck MackinnonBuck added this to the Backlog milestone May 22, 2024
@MackinnonBuck MackinnonBuck added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-identity Includes: Identity and providers enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

3 participants
@CollectorOfBolts @MackinnonBuck and others