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

Adding roles doesn't seem to be effective until the user logs out #8474

Closed
gaazkam opened this Issue Sep 10, 2018 — with docs.microsoft.com · 5 comments

Comments

Projects
None yet
3 participants

gaazkam commented Sep 10, 2018 — with docs.microsoft.com

This is one tidbit that caught me off-guard. I can't see it mentioned on this docu page. If I might suggest, should this be briefly mentioned in this docs page and perhaps explained somewhere else at lenght?

The thing I noticed is that if a user is added to a role via userManager.AddToRoleAsync(idenityUser, role) while they are logged in, context.User.IsInRole(role) will still return false until the user logs out and in again.

I tried to modify this sample app to allow admins promote regular users to managers. The promotion was not successfull until they logged out. I also tried to enhance the signalR chat app presented in these docs pages to support accounts and to allow mods to mute users via userManager.AddToRoleAsync(idenityUser, "Muted"). This should be enforced immediatelly, not when the user in question logs out.

Is there any docs pages that covers this issue?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@Rick-Anderson

This comment has been minimized.

Show comment
Hide comment
@Rick-Anderson

Rick-Anderson Sep 10, 2018

Contributor

@HaoK please respond.

Contributor

Rick-Anderson commented Sep 10, 2018

@HaoK please respond.

@HaoK

This comment has been minimized.

Show comment
Hide comment
@HaoK

HaoK Sep 10, 2018

Member

Yes roles are stored in the cookie, so any changes made to the users roles wouldn't be persisted into the cookie until the next time the cookie is regenerated (typically this happens automatically every 30 minutes or so due to the security stamp validator)

Member

HaoK commented Sep 10, 2018

Yes roles are stored in the cookie, so any changes made to the users roles wouldn't be persisted into the cookie until the next time the cookie is regenerated (typically this happens automatically every 30 minutes or so due to the security stamp validator)

This comment has been minimized.

Show comment
Hide comment
@gaazkam

gaazkam Sep 10, 2018

Is there any way to force a regeneration of this cookie? Invalidating the previous cookie maybe?

gaazkam commented Sep 10, 2018 — with docs.microsoft.com

Is there any way to force a regeneration of this cookie? Invalidating the previous cookie maybe?

@Rick-Anderson

This comment has been minimized.

Show comment
Hide comment
@Rick-Anderson

Rick-Anderson Sep 10, 2018

Contributor

@HaoK

any changes made to the users roles wouldn't be persisted into the cookie until the next time the cookie is regenerated (typically this happens automatically every 30 minutes or so due to the security stamp validator)

Or the user signs out, signs in again. - right?

Contributor

Rick-Anderson commented Sep 10, 2018

@HaoK

any changes made to the users roles wouldn't be persisted into the cookie until the next time the cookie is regenerated (typically this happens automatically every 30 minutes or so due to the security stamp validator)

Or the user signs out, signs in again. - right?

@HaoK

This comment has been minimized.

Show comment
Hide comment
@HaoK

HaoK Sep 10, 2018

Member

Yeah, the app should just do that explicitly on the page that added the role(signinManager.RefreshSignIn)

Member

HaoK commented Sep 10, 2018

Yeah, the app should just do that explicitly on the page that added the role(signinManager.RefreshSignIn)

Rick-Anderson added a commit that referenced this issue Sep 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment