Social Connected with Sitecore (Facebook) 4: Disconnect profile

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’.
2014-06-30_004340
Based on this, you could log out the user and delete the profile.

Advertisements

One thought on “Social Connected with Sitecore (Facebook) 4: Disconnect profile

  1. […] 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 […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s