Scenario -
A project I am working on has over 1000 registered contacts on dynamics CRM CE. We are rolling out a self-service portal to all of these contacts. Now normally, if it were a new portal user, they could just go to the Azure sign-in page and register on the portal. However, these contacts already have AD registration done as a part of an existing domain and we need to ensure that the contact history is maintained so we can't just create a new contact and instead have to map their existing contact from Dynamics CE to the existing AD credentials.
My understanding of how portal contacts work is limited at best but what I know for sure is that during the AD login the portal will search for existing contacts in CRM to see if any user name field on Contact table in CE matches the registered email or the GUID of the AD credential of the login. If no matching contact is found then it creates a new contact in CRM and assign it to the AD login. This is only applicable to active contacts. So if a valid contact is deactivated, portal will just go and create a new contact and assign the AD login to that contact. I tried working around this issue by overwriting the fields from a new contact after the first AD portal login but this doesn't seem to work even if everything matches for both contacts. In this scenario I keep getting the error that the email id and user name are taken.
So far I have searched Microsoft documentation for syncing contacts between D365 and AD but only references I could find online are for flows to copy an AD contact to Dynamics 365 CE/F&O or vice versa.
Any suggestions please?