How to disconnect your app from your users facebook account using spring social facebook

Spring social is an umbrella project (one of the Spring Framework projects), which contains a bunch of modules for connecting your spring application with different social media services like facebook, twitter, github, etc.

For a project we are currently developing I need to implement facebook integration for easy registration and login with facebook. There are plenty of documentations and tutorials out there, which describe how to connect users account with facebook using spring-social-facebook project, but practically no (at least I cannot find any) guidance how to disconnect. Disconnecting means removing (revoking) authorization of your app to access your users facebook account.


Here is my solution for that:

FacebookTemplate facebookTemplate = new FacebookTemplate(accessToken);
boolean authorized = facebookTemplate.isAuthorized();
if (authorized) {
    facebookTemplate.delete(userId, "permissions");

You have to fill accessToken and userId values according to current users context. When the delete method successfully executed (without throwing any exception), your applications authorization will be removed from facebook account of your user.

See official facebook API documentation for more information about de-authorization of your app.