<?php // Start a session and load the OAuth library. session_start(); require_once __DIR__ . '/oauth-client/src/google.class.php'; // Delete the access token if needed. if (isset($_GET["del_token"]) && isset($_SESSION["g_token"])) { unset($_SESSION["g_token"]); } // Create a new Google object. $google = new OAuthGoogle("0000000000000000", "0000000000000000000000000000000000000000", array("session_prefix" => "g_")); // Output a Login Button. echo $google->loginButton("Login with Google+", "https://example.com/google-1/code.php", array("https://www.googleapis.com/auth/plus.login")); // If an access token exists (OAuth2::accessToken() does not return null), fetch the current user's data. if ($google->accessToken() != null) { // The user is logged in, you can do whatever you like here. // In this example we just print the profile data, along with the profile picture and permissions. $profile = $google->userProfile(); echo "<pre>" . print_r($profile, true) . "</pre><br /><br />\n\n"; } else { echo "You have not granted access to Google. Click the link above.\n"; }
ivhUFo8IaOv58YhZywJBANhgZBTITngaSdEL2IbtSxfm/kLNKi+LqBrXGuxLKfjj XtSdMrU3hKHSSCEI9VyLtsn45QWRB4nScfZxEvcEuwU= -----END RSA PRIVATE KEY----- EOF; $public_key = <<<EOF -----BEGIN CERTIFICATE----- MIICyDCCAjGgAwIBAgIJAKIMYtsMjN/+MA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV fajlsdjflksajlkfjsakljflksjflksjA1UEBxMNTW91bnRhaW4gVmlldzEZMBcG A1UEAxMQZGVtby50aGlucGhwLmNvbTAeFw0xMTA0MDMwOTIyNDlaFw0xMjA0MDIw OTIyNDlaME0xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91 bnRhaW4gVmlldzEZMBcGA1UEAxMQZGVtby50aGlucGhwLmNvbTCBnzANBgkqhkiG 9w0BAQEFAAOBjQAwgYkCgYEAscJW0VumqMev7yTATcea5RiIJapKrqlurGNYUuWF m52NNima9eHCrSsZc3ki6ec7B5bCKqtnEYX4HeKHErDzxAS/oQ72foX+spL7jFMP D4bvpvVEIFDVDHkFR9h568y6qjE+hyscMw0r38YZ+rKTfcuWlNgOuxW4Qkd324hw VKECAwEAAaOBrzCBrDAdBgNVHQ4EFgQUO7UMiEBSFf2pit66Up0RU2S4KEgwfQYD VR0jBHYwdIAUO7UMiEBSFf2pit66Up0RU2S4KEihUaRPME0xCzAJBgNVBAYTAlVT MQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEZMBcGA1UEAxMQ ZGVtby50aGlucGhwLmNvbYIJAKIMYtsMjN/+MAwGA1UdEwQFMAMBAf8wDQYJKoZI hvcNAQEFBQADgYEAqrx6/gMybqWQfzq26pG9ziFjZ5Ou5VQlzRCXgGL6hONzsFX+ PpvtwyHfFUFX+ydKGfqt60/6V4HAFkkN4Z9/57iMgCHeInaEpq+AS7hjyS2iRnq5 Hoj7ALKFxeIE4vqHbB5eslt9GdHSsAHMaOBsFwuj+EMaG8Stdlwak/TDcpA= -----END CERTIFICATE----- EOF; $oauth = new OAuthGoogle(array('id' => 'demo.thinphp.com', 'secret' => false, 'private_key' => $private_key, 'public_key' => $public_key, 'callback' => 'http://demo.thinphp.com/app/ext/authentication/oauth/oauth_google.php?step=callback', 'scope' => OAuthGoogle::scopes('contacts'))); function process($oauth) { $s = $oauth->fetch('http://www.google.com/m8/feeds/contacts/default/base', 'GET'); $_SESSION['user'] = $s['feed']['author']['name']; header('Location: /'); } require 'oauth_inc.php';
<?php // Start a session and load the OAuth library. session_start(); require_once __DIR__ . '/oauth-client/src/google.class.php'; // Create a new Facebook object. $google = new OAuthGoogle("0000000000000000", "0000000000000000000000000000000000000000", array("session_prefix" => "g_")); // Try to fetch an access token with the code in $_GET["code"]. Also check the state in $_GET["state"]. try { $google->getAccessTokenFromCode("http://example.com/google-1/code.php"); // -------- // If we got here, no error was thrown and an access token was successfully retrieved from the code. // Output the code and access token. echo "Success! Click the link at the bottom of the page to return home and fetch data using the access token.<br />\n"; echo "Code: " . htmlspecialchars($_GET["code"]) . "<br />\n"; echo "Access Token: " . htmlspecialchars($google->accessToken()) . "\n<br /><br />\n\n"; } catch (Exception $error) { echo "Error - Click the link at the bottom of the page to return home and try again: " . $error->getMessage() . "\n<br /><br />\n\n"; } // Output a link to the homepage to fetch data using the access token. echo "<a href=\"./\">Home</a>\n";
VKECAwEAAaOBrzCBrDAdBgNVHQ4EFgQUO7UMiEBSFf2pit66Up0RU2S4KEgwfQYD VR0jBHYwdIAUO7UMiEBSFf2pit66Up0RU2S4KEihUaRPME0xCzAJBgNVBAYTAlVT MQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEZMBcGA1UEAxMQ ZGVtby50aGlucGhwLmNvbYIJAKIMYtsMjN/+MAwGA1UdEwQFMAMBAf8wDQYJKoZI hvcNAQEFBQADgYEAqrx6/gMybqWQfzq26pG9ziFjZ5Ou5VQlzRCXgGL6hONzsFX+ PpvtwyHfFUFX+ydKGfqt60/6V4HAFkkN4Z9/57iMgCHeInaEpq+AS7hjyS2iRnq5 Hoj7ALKFxeIE4vqHbB5eslt9GdHSsAHMaOBsFwuj+EMaG8Stdlwak/TDcpA= -----END CERTIFICATE----- EOF; $oauth = new OAuthGoogle( array( 'id' => 'demo.thinphp.com', 'secret' => false, 'private_key' => $private_key, 'public_key' => $public_key, 'callback' => 'http://demo.thinphp.com/app/ext/authentication/src/oauth_google.php?step=callback', 'scope' => OAuthGoogle::scopes('contacts'), ) ); function process($oauth) { $s = $oauth->fetch('http://www.google.com/m8/feeds/contacts/default/base', 'GET'); $_SESSION['user'] = $s['feed']['author']['name']; header('Location: /'); } require('oauth_inc.php');