I’ve seen a few topics touch on this issue, but nothing quite seems to address it.
Basically, our company was purchased. This means all users are moving from @old_company.com to @new_company.com
I have a map of old to new email addresses. What I would like to do is add the @new_company.com email address for a user and automatically confirm it. Otherwise they need to go through the confirmation emails themselves, which realistically won’t happen.
Is there any way I can add a secondardy email as admin and automatically confirm it?
Simon mentions the following
But it’s not clear to me how this works. How can it sync an email address to an account, if the address is not yet confirmed? Does this mean I should/could
add secondary email for user via api
(maybe) disable outgoing email for 10 minutes so no confirmation email is sent
enable saml sync email
user accounts confirm and update when they sign in with saml
Note, we are also changing saml provider in this example
Even though the secondary email has not been confirmed, does the above setup mean that when they try to log in with the email for the first time, it will be automatically confirmed and tied to the account?
Just as a note, one issue I misunderstood was the confirmation email. As admin you get two emails, one to confirm your old email, then a second to confirm the change.
I assumed this applied to all users, but with the setting in the image above, you can set it to apply to only staff. This means users would only get the one email to confirm the change.
Still need to figure out how to automatically confirm the email for the user though
I’m not sure there is a way to automatically confirm through the UI/API. I think if there’s SSO then the email/identity confirmation is handled by them? In which case using the sso_sync would pull in the already confirmed data/email and use that as ‘trustworthy’.
A little bit of fact-checking later…
The /admin/users/sync_sso is only for DiscourseConnect. I think you already knew that, but I’ll say it out loud for anyone reading this later.
But there’s also the auth_overrides_emails admin setting which may be useful for this.
Essentially, if your SAML provider is sending a verified email, and auth_overrides_emails is set, Discourse will start using the new email without any confirmation being emailed out.
This is not a direct answer to your question, but: In the case of mass-renaming of email-addresses, you could do it via rails console:
o = "@old_company.com"
n = "@new_company.com"
UserEmail.where("email LIKE ?","%#{o}").each do |ue|
ue.email.sub! o,n
ue.save!
end
If you favor adding a secondary email address:
o = "@old_company.com"
n = "@new_company.com"
UserEmail.where("email LIKE ?","%#{o}").each do |ue|
sm = UserEmail.new
sm.user_id = ue.id
sm.email = ue.email.sub! o,n
sm.save!
end
Thanks for the suggestions. I gave them a try in the following way:
1. Add secondary email to user via api
The email is unconfirmed, but tied to the account
2. Configure the following settings:
I forgot to set the saml sync to true, however I don’t think that would have affected the outcome. The issue still seems to be conflict in terms of the email confirmation.
3. Result
The result was the a new user account was created based on the new company email. Worst case I could merge these, but that is a really nasty worst case.
I can still see the unconfirmed email in the old account. I try to resend the confirmation just to see what would happen but I get a 403 error(Forbidden).
It looks like the email needs to be confirmed first before we can syncronise them
Unless there’s something I’m missing, it looks like I need a way to confirm the second email.
I wonder if this still has the same issue in terms of confirmation, or are they assumed to be confirmed? An additional complexity is that the user part of user@company.com has also changed. But I suspect that would mean we run through a csv of mappings between the old and new emails.
I think it might be doing this, in that it is validating a SAML account based on the email address and SAML server used to log in. The problem is that it’s a completely different SAML IDP (New Company).
Consequently it correctly over-rides/creates the email to be the SAML email, but it does this for a brand new account because the Discourse account is not associated to the new email address.
However, if the existing account has the new saml email addres already confirmed in Discourse, then the login is smooth and it becomes their new saml login email.
To the best of my knowledge this hasn’t happened. For another platform we needed to get a list of the emails ourselves and do the mapping.
It looks more and more like this is the way to proceed. We’re hosted by you guys so I’ll pass this on to our CSM and follow up on this topic with any progress.