User Groups Not being updated
See original GitHub issueDescribe the bug
Amplify with Cognito. If I update a user’s groups, I’m not seeing a great way to update the user’s groups. My hope is that this will/should automatically update.
To Reproduce Steps to reproduce the behavior:
- Check user’s groups
async currentUserGroups(): Promise<string[]> {
const currentSession: CognitoUserSession = await Auth.currentSession();
let groups: string[] = [];
if (currentSession) {
groups = currentSession.getIdToken().payload['cognito:groups'];
}
return groups;
}
Expected behavior
When I update the user’s, I would expect Auth.currentSession()
to do the right thing.
Sample code I was able to get the user session to be updated, but this work-around doesn’t seem right:
async updateUserGroups() {
const currentUser: CognitoUser = await Auth.currentAuthenticatedUser();
const userSession: CognitoUserSession = currentUser.getSignInUserSession();
const refreshToken = userSession.getRefreshToken();
currentUser.refreshSession(refreshToken, (err, session) => {
currentUser.setSignInUserSession(session);
});
}
Or at least it’s pretty painful. If this can’t happen automatically, is there a way to have a method on CognitoUser
… something like updateUserGroups()
?
If this is the “correct” or “best” way to handle this, then at the very least this should be heavily documented. I would be happy to help in any way that I can.
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:26 (8 by maintainers)
Top Results From Across the Web
Group membership not updating on PC
Solution: Seems like you have to JUST log off and then back in, and it is updating the memberships. A reboot is NOT...
Read more >Group membership changes do not update over some VPN ...
Describes a situation in which VPN users might experience resource access or configuration problems after their group membership changes.
Read more >Why are user groups not updating when logging out and in ...
Go to a virtual terminal; Log in; loginctl terminate-user "$USER"; Press Win + F1 to return to the login form (Tried on Ubuntu)....
Read more >How do you force an update to a user's group membership in ...
Log off and back in should do the trick, no need to reboot. Group memberships are applied at login. – Charlie Wilson. Dec...
Read more >How to Refresh AD Groups Membership without Reboot/Logoff?
To update group membership and apply the assigned permissions or Group Policies, you need to restart the computer (if a computer account was ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@haverchuck - this seems like a pretty big security risk to me … shouldn’t this be a marked a bug and escalated?
@malcomm I’ve learned that the downstream services are just doing signing validation of the access token, not checking permissions.
We’re having conversations on how to best resolve this on both the client & server-side, but unfortunately don’t have that answer today.
In the interim, knowing that polling/intervals can be expensive for batter life, I’d recommend the following:
Some examples of refreshing tokens have already been provided in this thread, among others:
Thanks for staying on top of this @malcomm! Hopefully the client-side token refresh is a reasonable stopgap while we can research a scalable solution for the server-side.