To ensure users have the necessary permissions for my app, I plan to redirect them to the oauth page if any required permissions are missing.
However, when attempting to redirect from the FB.api callback function with the code below, I seem to encounter an infinite loop. Any suggestions on how to resolve this issue?
var requiredPermissions = ['publish_actions', 'email', 'user_birthday', 'user_location'],
permsString = requiredPermissions.join(','),
permissionsUrl = 'https://www.facebook.com/dialog/oauth';
permissionsUrl += '?client_id=' + config.facebook.appId;
permissionsUrl += '&redirect_uri=' + encodeURI(canvasUrl);
permissionsUrl += '&scope=' + permsString;
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
FB.api('/me/permissions', function(response) {
var keys = _.keys(response.data[0]),
diff = _.difference(requiredPermissions, keys);
// Redirect user to auth again if they've removed any required permissions
if (diff.length) {
window.location.href = permissionsUrl; // Results in endless loop
// window.location.href = 'http://randomwebsite.com'; // Redirects successfully
}
});
}
}, true);