You are here

function fb_require_authorization in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 7.3 fb.module \fb_require_authorization()

Helper function to ensure user has authorized an application.

Similar to the old require_login() provided by the old facebook API. Works by redirecting the user as described in http://developers.facebook.com/docs/authentication/.

@TODO handle users who skip.

1 call to fb_require_authorization()
fb_tab_config_form in ./fb_tab.module
Build the tab config form. Invokes hook_fb_tab() to get the custom settings.

File

./fb.module, line 940
This is the core required module of Drupal for Facebook.

Code

function fb_require_authorization($fb = NULL, $destination = NULL) {
  if (!$fb) {
    $fb = $GLOBALS['_fb'];
  }
  if (!$fb) {
    throw new Exception(t('Failed to authorize facebook application.  Could not determine application id.'));
  }
  $fbu = fb_facebook_user($fb);
  if (!$fbu) {
    $client_id = $fb
      ->getAppId();
    $redirect_uri = $destination ? $destination : url(fb_scrub_urls($_REQUEST['q']), array(
      'absolute' => TRUE,
      'fb_canvas' => fb_is_canvas(),
    ));

    // Which permissions to prompt for?
    $perms = array();
    drupal_alter('fb_required_perms', $perms);
    $scope = implode(',', $perms);
    $url = "https://graph.facebook.com/oauth/authorize?client_id={$client_id}&scope={$scope}&redirect_uri={$redirect_uri}";
    drupal_goto($url);
  }
  else {
    return $fbu;
  }
}