Re-provision Slack after primary email changes - #307
Conversation
Sync The branch
|
One possible fix could be to automatically reprovision Slack whenever an identity's primary email changes. Right now, once identity.slack_id is set, SAML provisioning immediately returns: This means if someone changes their primary email before or after provisioning, the Slack link is never revalidated.
This would keep the Slack link in sync with the identity's current email and would have prevented the duplicate account issue I ran into. This pr used this approach! |
|
We don't want to re-provision a user's Slack when they change their email - this inadvertently creates unused Slack accounts. User signs up > gets Slack Acct. #A > changes email on Slack > clicks sign in on Auth > Slack Acct. #B gets created.
The solution to this is just to email |
This is not the correct flow this would activate. But.. If we dont want it to create account we can edit that. |
|
We want people to have one slack account though.. because that is the Slack account that is 'verified' |
Re-provision Slack after primary email changes
What this PR does
When a user changes their primary email, we now reprovision their Slack account after the email change is completed.
The reprovisioning logic:
Tests
Why?
I originally had a Slack account with email A. Later that account got deactivated. Before joining Slack again, I changed my primary email in Hack Club Auth to email B.
Then I clicked Join Slack.
SCIMService.find_or_create_usergets called from bothLoginsControllerandSamlController:Inside
app/services/scim_service.rb, it looks for an existing Slack user using the current primary email:and find_existing_user_by_email does:
Since my HCA email was now email B, it looked for a Slack account with email B. My old Slack account still had email A, so it couldn't find it and instead created a completely new Slack account.
After that, HCA saved the new Slack ID to my identity.
Later I changed my HCA email back to email A and my old Slack account was reactivated. But SAML still logged me into the new account because it only provisions if
slack_idis missing:So it never tried to find my original account again.
I think the main issue is that provisioning only looks at the current email the first time. If someone changes their email before provisioning, it's really easy to accidentally create a duplicate Slack account that stays linked forever.