function fb_require_authorization in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.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.
2 calls to fb_require_authorization()
- fb_devel_page in ./
fb_devel.module - Provides a page with useful debug info.
- 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 1043 - 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(current_path(), array(
'absolute' => TRUE,
'fb_canvas' => fb_is_canvas(),
));
$url = "https://graph.facebook.com/oauth/authorize?client_id={$client_id}&redirect_uri={$redirect_uri}";
// Which permissions to prompt for?
$perms = array();
drupal_alter('fb_required_perms', $perms);
if (count($perms)) {
$url .= '&scope=' . implode(',', $perms);
}
if (fb_is_canvas() || fb_is_tab()) {
fb_iframe_redirect($url);
}
else {
header('Location: ' . $url);
// drupal_goto is for internal redirects only.
}
}
else {
return $fbu;
}
}