You are here

function drupagram_account_oauth_validate in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.pages.inc \drupagram_account_oauth_validate()

If OAuth is enabled, intercept submission of 'Add Account' form on user/%/edit/drupagram page and redirect to Instagram for auth.

1 string reference to 'drupagram_account_oauth_validate'
drupagram_account_form in ./drupagram.pages.inc
Form to add a Instagram account

File

./drupagram.pages.inc, line 311
Drupagram admin page callaback functions.

Code

function drupagram_account_oauth_validate($form, &$form_state) {
  module_load_include('lib.php', 'oauth_common');
  module_load_include('lib.php', 'drupagram');
  $callback_uri = url('instagram/oauth', array(
    'absolute' => TRUE,
  ));
  $client_id = variable_get('drupagram_client_id', '');
  $client_secret = variable_get('drupagram_client_secret', '');
  if ($client_id == '' || $client_secret == '') {
    form_set_error('', t('Please configure your Instagram client id and secret.'));
  }
  $drupagram = new InstagramOAuth($client_id, $client_secret);

  // $token = $drupagram->get_request_token();
  $_SESSION['drupagram_oauth']['account'] = user_load($form['uid']['#value']);

  // $_SESSION['drupagram_oauth']['token'] = $token;
  $_SESSION['drupagram_oauth']['destination'] = $_GET['q'];
  drupal_goto($drupagram
    ->get_authorize_url($callback_uri));
}