Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gauth_login_user_login_submit() {
- if (variable_get('gauth_login_client_id', FALSE)) {
- $info = libraries_load('google-api-php-client');
- if (!$info['loaded']) {
- drupal_set_message(t("Can't authenticate with google as library is missing check Status report or Readme for requirements"), 'error');
- return FALSE;
- }
- $client = new Google_Client();
- $client->setApplicationName("Google OAuth2");
- $client->setClientId(variable_get('gauth_login_client_id'));
- $client->setClientSecret(variable_get('gauth_login_client_secret'));
- $client->setRedirectUri(gauth_callback_url());
- $client->setDeveloperKey(variable_get('gauth_login_developer_key'));
- $scopes = gauth_google_services_scopes();
- $client->addScope($scopes['oauth2']);
- if (!isset($_SESSION['gauth_login_state'])) {
- $state = array(
- 'src' => 'gauth_login',
- 'hash' => md5(rand())
- );
- if (isset($_GET['destination'])) {
- $state['destination'] = $_GET['destination'];
- unset($_GET['destination']);
- }
- }
- else {
- $state = $_SESSION['gauth_login_state'];
- }
- $_SESSION['gauth_login_state'] = $state;
- $state = drupal_json_encode($state);
- $client->setState($state);
- $url = $client->createAuthUrl();
- if ($restrict_domain = variable_get('gauth_login_domain_restriction', FALSE)) {
- $url .= '&hd=' . $restrict_domain;
- }
- drupal_goto($url);
- }
- else {
- drupal_set_message(t('Gauth Login is not configured. Please contact site administrator'), 'error');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement