Skip to content

Commit

Permalink
finish google-plus integration
Browse files Browse the repository at this point in the history
  • Loading branch information
João Neto committed Sep 18, 2014
1 parent e148060 commit 7ef3fae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
37 changes: 30 additions & 7 deletions google-plus/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@

set_include_path(get_include_path() . PATH_SEPARATOR . plugin_dir_path(__FILE__));
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';

if (isset($_GET['code'])) {
$code = $_GET['code'];
$client_id = get_option('social_connect_google_plus_client_id');
$client_secret = get_option('social_connect_google_plus_client_secret');
$redirect_uri = SOCIAL_CONNECT_GOOGLE_PLUS_REDIRECT_URL;

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);

if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else if (isset($code)) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
}

$client->authenticate($code);
$token = json_decode($client->getAccessToken());

$attributes = $client->verifyIdToken($token->id_token, $client_id)
->getAttributes();
$gplus_id = $attributes["payload"]["sub"];
$google_oauthV2 = new Google_Service_Oauth2($client);
$user = $google_oauthV2->userinfo->get();
$google_id = $user['id'];
$email = $user['email'];
$first_name = $user['givenName'];
$last_name = $user['familyName'];
$profile_url = $user['link'];


$signature = social_connect_generate_signature($access_token);
$signature = social_connect_generate_signature($google_id);

?>
<html>
Expand All @@ -30,7 +48,11 @@
function init() {
window.opener.wp_social_connect({'action' : 'social_connect', 'social_connect_provider' : 'google-plus',
'social_connect_signature' : '<?php echo $signature ?>',
'social_connect_access_token' : '<?php echo $access_token ?>'});
'social_connect_google_id' : '<?php echo $google_id ?>',
'social_connect_email' : '<?php echo $email ?>',
'social_connect_first_name' : '<?php echo $first_name ?>',
'social_connect_last_name' : '<?php echo $last_name ?>',
'social_connect_profile_url' : '<?php echo $profile_url ?>'});

window.close();
}
Expand All @@ -39,4 +61,5 @@ function init() {
<body onload="init();"></body>
</html>
<?php
}
}
?>
8 changes: 7 additions & 1 deletion social-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ function sc_social_connect_process_login( $is_ajax = false ) {
$user_login = strtolower( $sc_first_name.$sc_last_name );
break;
case 'google-plus':
die('asdf');
$sc_provider_identity = $_REQUEST['social_connect_google_id'];
social_connect_verify_signature( $sc_provider_identity, $sc_provided_signature, $redirect_to);
$sc_email = $_REQUEST['social_connect_email'];
$sc_first_name = $_REQUEST['social_connect_first_name'];
$sc_last_name = $_REQUEST['social_connect_last_name'];
$sc_profile_url = $_REQUEST['social_connect_profile_url'];
$user_login = strtolower( $sc_first_name.$sc_last_name );
break;
case 'yahoo':
$sc_provider_identity = $_REQUEST[ 'social_connect_openid_identity' ];
Expand Down

0 comments on commit 7ef3fae

Please sign in to comment.