You are here

function media_acquiadam_deauth_page in Media: Acquia DAM 7

Clears the current user's authentication token.

Return value

array A page render array.

1 string reference to 'media_acquiadam_deauth_page'
media_acquiadam_menu in ./media_acquiadam.module
Implements hook_menu().

File

includes/media_acquiadam.pages.inc, line 93
Page callback implementations.

Code

function media_acquiadam_deauth_page($account = NULL) {
  try {
    $client = AcquiaDAM_API::getClient('acquiadam-server-auth');
    $client
      ->getOAuth2Client()
      ->clearToken();

    // Nuke the oauth2 session data just to be sure we cleared everything.
    unset($_SESSION['oauth2_client']);
  } catch (Exception $x) {
    watchdog_exception('media_acquiadam', $x);
    drupal_set_message(t('There was a problem clearing the token.'), 'error');
  }
  $success_message = t('Your OAuth2 DAM access token has been cleared.');

  // If a destination argument was set we should send the user back to where
  // they came from.
  if (!empty($_GET['destination'])) {
    drupal_set_message($success_message, 'status');
    drupal_goto($_GET['destination']);
  }
  $build = [];

  // Build a simple status page if someone goes directly to the page.
  $build['message'] = [
    '#type' => 'markup',
    '#markup' => '<p>' . $success_message . '</p>',
  ];
  return $build;
}