You are here

function fb_client_auth_url in Drupal for Facebook 7.4

Produce a client side auth URL as described in https://developers.facebook.com/docs/authentication/client-side/

7 calls to fb_client_auth_url()
fb_admin_token_generate_process in ./fb.admin.inc
fb_connect_translated_menu_link_alter in ./fb_connect.module
Implements hook_translated_menu_link_alter().
fb_devel_page in ./fb_devel.module
Provides a page with useful debug info.
fb_devel_page_test in ./fb_devel.module
fb_post_form_node_form_alter in ./fb_post.module
Implements hook_form_BASE_FORM_ID_alter(). Implements hook_form_node_form_alter().

... See full list

File

./fb.module, line 977

Code

function fb_client_auth_url($options = array()) {

  // TODO: clean up the fba vs client_id confusion.
  if (!empty($options['client_id'])) {
    $options['fba'] = $options['client_id'];
  }

  // defaults
  if (empty($options['fba'])) {
    $options = fb_get_app();
  }
  if (empty($options['fba'])) {

    // No application configured.  Any link we try to generate will result in error on facebook.com.
    return NULL;
  }

  // Calculate a redirect uri which will be part of our URL.
  $options += array(
    'redirect_uri' => fb_auth_redirect_uri(current_path(), array(
      'query' => array(
        'client_id' => $options['fba'],
      ),
    )),
    'scope' => '',
  );

  // debug

  //$options['redirect_uri'] = 'http://work.electricgroups.com/dave/fridge/htdocs/fb/devel';

  // http://developers.facebook.com/docs/authentication/server-side/
  $query = array(
    'client_id' => $options['fba'],
    'redirect_uri' => $options['redirect_uri'],
    'response_type' => 'token',
  );

  // Leave scope out, unless it is explicitly in options, so that it can be appended in fb.js.
  if (is_array($options['scope'])) {
    $options['scope'] = implode(',', $options['scope']);
  }
  if (!empty($options['scope'])) {
    $query['scope'] = $options['scope'];
  }
  $url = url('https://www.facebook.com/dialog/oauth', array(
    'query' => $query,
  ));
  return $url;
}