daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jun 19th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gauth_login_user_login_submit() {
  2.   if (variable_get('gauth_login_client_id', FALSE)) {
  3.     $info = libraries_load('google-api-php-client');
  4.     if (!$info['loaded']) {
  5.       drupal_set_message(t("Can't authenticate with google as library is missing check Status report or Readme for requirements"), 'error');
  6.       return FALSE;
  7.     }
  8.     $client = new Google_Client();
  9.     $client->setApplicationName("Google OAuth2");
  10.     $client->setClientId(variable_get('gauth_login_client_id'));
  11.     $client->setClientSecret(variable_get('gauth_login_client_secret'));
  12.     $client->setRedirectUri(gauth_callback_url());
  13.     $client->setDeveloperKey(variable_get('gauth_login_developer_key'));
  14.     $scopes = gauth_google_services_scopes();
  15.     $client->addScope($scopes['oauth2']);
  16.     if (!isset($_SESSION['gauth_login_state'])) {
  17.       $state = array(
  18.         'src' => 'gauth_login',
  19.         'hash' => md5(rand())
  20.       );
  21.       if (isset($_GET['destination'])) {
  22.         $state['destination'] = $_GET['destination'];
  23.         unset($_GET['destination']);
  24.       }
  25.     }
  26.     else {
  27.       $state = $_SESSION['gauth_login_state'];
  28.     }
  29.     $_SESSION['gauth_login_state'] = $state;
  30.     $state = drupal_json_encode($state);
  31.     $client->setState($state);
  32.  
  33.     $url = $client->createAuthUrl();
  34.     if ($restrict_domain = variable_get('gauth_login_domain_restriction', FALSE)) {
  35.       $url .= '&hd=' . $restrict_domain;
  36.     }
  37.  
  38.     drupal_goto($url);
  39.   }
  40.   else {
  41.     drupal_set_message(t('Gauth Login is not configured. Please contact site administrator'), 'error');
  42.   }
  43. }
RAW Paste Data
Top