Disconnecting a facebok profile from sitecore can entail 2 activities:
- Revoke permission granted to your application in the user facebook profile
- Delete the facebook user information from the Sitecore Core database
- If the user was created from the facebook login, log out the user and then delete the user from sitecore
Revoke permission granted to your application in the user facebook profile
Here we will be using the facebook js API to deauthorize our application
<script type="text/javascript"> function fbDeauth() { FB.api('/' + '<%= Sitecore.Context.User.Profile.GetCustomProperty("fb_id")%>' + '/permissions', 'DELETE', function (res) { if (res === true) { alert('app deauthorized'); } else if (res.error) { alert("res.error" + res.error.type + ': ' + res.error.message); } else { alert("Else:" + res); } }); return false; } </script>
Delete the facebook user information from the Sitecore Core database
You could loop through all the relevant (prefix ‘fb_’) user properties and delete them:
foreach (var customPropertyName in Sitecore.Context.User.Profile.GetCustomPropertyNames()) { if (customPropertyName.Contains("fb_")) Sitecore.Context.User.Profile.RemoveCustomProperty(customPropertyName) }
If the user was created from the facebook login, log out the user and then delete the user from sitecore
If the user was created using a facebook login, the username will be suffixed with ‘_facebook’.
Based on this, you could log out the user and delete the profile.
Advertisements
[…] This video speaks of all the functionalities as described in the following blog posts: Social Connected with Sitecore (Facebook) 1: Setup & Posting messages Social Connected with Sitecore (Facebook) 2: Access facebook information Social Connected with Sitecore (Facebook) 3: Post ad hoc messages to facebook Social Connected with Sitecore (Facebook) 4: Disconnect profile […]
LikeLike