You are here

function fboauth_action_page in Facebook OAuth (FBOAuth) 7

Same name and namespace in other branches
  1. 6 includes/fboauth.fboauth.inc \fboauth_action_page()
  2. 7.2 includes/fboauth.fboauth.inc \fboauth_action_page()

Menu callback; The main page for processing OAuth login transactions.

Parameters

string $action : The action being requested. Currently supports the following:

  • connect: Initiate Facebook connection and log a user in.
  • deauth: Remove the exisitng Facebook connection access.
1 string reference to 'fboauth_action_page'
fboauth_menu in ./fboauth.module
Implements hook_menu().

File

includes/fboauth.fboauth.inc, line 17
Provides functions used during Facebook login processes.

Code

function fboauth_action_page($action) {
  global $user;

  // TODO: Support loading of more than one App ID and App Secret.
  $app_id = variable_get('fboauth_id', '');
  $app_secret = variable_get('fboauth_secret', '');
  $action_name = $action['name'];
  $error_message = t('The Facebook login could not be completed due to an error. Please create an account or contact us directly. Details about this error have already been recorded to the error log.');
  if (!($app_id && $app_secret)) {
    watchdog('fboauth', 'A Facebook login was attempted but could not be processed because the module is not yet configured. Vist the <a href="!url">Facebook OAuth configuration</a> to set up the module.', array(
      '!url' => url('admin/config/people/fboauth'),
    ));
  }
  elseif (isset($_REQUEST['error'])) {
    $link = fboauth_action_link_properties($action_name, $app_id);
    watchdog('fboauth', 'A user refused to allow access to the necessary
      Facebook information (@permissions) to login to the site.', array(
      '@permissions' => $link['query']['scope'],
    ));
    $error_message = t('This site requires access to information in order to
      log you into the site. If you like, you can
      <a href="!facebook">sign in with Facebook again</a> or
      <a href="!register">through the standard username/password registration</a>.', array(
      '!facebook' => url($link['href'], array(
        'query' => $link['query'],
      )),
      '!register' => url('user/register'),
    ));
  }
  elseif (!isset($_REQUEST['code'])) {
    watchdog('fboauth', 'A Facebook request code was expected but no authorization was received.');
  }
  elseif ($access_token = fboauth_access_token($_REQUEST['code'], $action_name, $app_id, $app_secret)) {
    $destination = fboauth_action_invoke($action_name, $app_id, $access_token);
    if (empty($destination)) {
      $destination = isset($_REQUEST['destination']) ? $_REQUEST['destination'] : '<front>';
    }
    drupal_goto($destination);
  }

  // In the event of an error, we stay on this page.
  return $error_message;
}