From 7ef3faef56c53b902a8079d02580903b9ddb312b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neto?= Date: Wed, 17 Sep 2014 21:59:11 -0300 Subject: [PATCH] finish google-plus integration --- google-plus/callback.php | 37 ++++++++++++++++++++++++++++++------- social-connect.php | 8 +++++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/google-plus/callback.php b/google-plus/callback.php index b9c163e..783c922 100644 --- a/google-plus/callback.php +++ b/google-plus/callback.php @@ -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); ?> @@ -30,7 +48,11 @@ function init() { window.opener.wp_social_connect({'action' : 'social_connect', 'social_connect_provider' : 'google-plus', 'social_connect_signature' : '', - 'social_connect_access_token' : ''}); + 'social_connect_google_id' : '', + 'social_connect_email' : '', + 'social_connect_first_name' : '', + 'social_connect_last_name' : '', + 'social_connect_profile_url' : ''}); window.close(); } @@ -39,4 +61,5 @@ function init() { \ No newline at end of file diff --git a/social-connect.php b/social-connect.php index 52a6a2a..d89506e 100644 --- a/social-connect.php +++ b/social-connect.php @@ -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' ];