You are here

function drupagram_oauth_callback_form_validate in Drupagram 6

Same name and namespace in other branches
  1. 7 drupagram.pages.inc \drupagram_oauth_callback_form_validate()

Validate results from Instagram OAuth return request.

File

./drupagram.pages.inc, line 247
Provieds drupagram forms.

Code

function drupagram_oauth_callback_form_validate(&$form, &$form_state) {
  $client_id = variable_get('drupagram_client_id', '');
  $client_secret = variable_get('drupagram_client_secret', '');
  $callback_uri = url('instagram/oauth', array(
    'absolute' => TRUE,
  ));
  if ($client_id == '' || $client_secret == '') {
    form_set_error('', t('Please configure your Instagram consumer key and secret.'));
  }
  if (isset($_SESSION['drupagram_oauth'])) {
    $form_state['drupagram_oauth'] = $_SESSION['drupagram_oauth'];
    unset($_SESSION['drupagram_oauth']);
  }
  else {
    form_set_error('oauth_token', 'Invalid Instagram OAuth request: Session mismatch.');
  }
  module_load_include('lib.php', 'oauth_common');
  module_load_include('lib.php', 'drupagram');
  module_load_include('inc', 'drupagram');
  if ($drupagram = new InstagramOAuth($client_id, $client_secret, $callback_uri)) {
    if ($response = $drupagram
      ->get_access_token($form_state['values']['code'], $callback_uri)) {
      $form_state['drupagram_oauth']['response'] = $response;
    }
    else {
      form_set_error('oauth_token', t('Invalid Instagram OAuth request: Token invalid'));
    }
  }
  else {
    form_set_error('oauth_token', t('Invalid Instagram OAuth request: Invalid oAuth Settings'));
  }
}