You are here

function bynder_oauth_login in Bynder 7

1 string reference to 'bynder_oauth_login'
bynder_menu in ./bynder.module
Implements hook_menu().

File

includes/bynder.browser.inc, line 54
Manages the Bynder media browser functionality

Code

function bynder_oauth_login() {
  if (isset($_GET['oauth_token'])) {
    BynderMediaApi::getBynderApi()
      ->finishOAuthTokenRetrieval();
    return [
      '#markup' => '<script>window.close()</script>',
      '#allowed_tags' => [
        'script',
      ],
    ];
  }
  elseif (isset($_GET['oauth_check_login'])) {
    $tokens = BynderMediaApi::getBynderApi()
      ->hasAccessToken();
    if ($tokens && !isset($tokens['isRequestToken'])) {
      drupal_json_output(true);
    }
    elseif (isset($_SESSION['bynderLoginError'])) {
      unset($_SESSION['bynderLoginError']);
      drupal_set_message(t('There is something wrong with your Bynder configuration, please confirm the details
                in @settings and try again', array(
        '@settings' => url('admin/config/media/bynder', array(
          'absolute' => true,
        )),
      )), 'error');
      drupal_json_output(true);
    }
    else {
      drupal_json_output(false);
    }
  }
  else {
    try {
      $url = BynderMediaApi::getBynderApi()
        ->initiateOAuthTokenRetrieval();
      drupal_goto($url);
    } catch (Exception $e) {
      $_SESSION['bynderLoginError'] = true;
      return [
        '#markup' => '<script>window.close()</script>',
        '#allowed_tags' => [
          'script',
        ],
      ];
    }
  }
}