Version Description
All existing versions are functionally identical - no need to upgrade.
Download this release
Release Info
Developer | danlester |
Plugin | Google Apps Login |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- google_apps_login.php +338 -0
- googleclient/Google_Client.php +471 -0
- googleclient/LICENSE +203 -0
- googleclient/NOTICE +4 -0
- googleclient/README +40 -0
- googleclient/auth/Google_AssertionCredentials.php +103 -0
- googleclient/auth/Google_Auth.php +36 -0
- googleclient/auth/Google_AuthNone.php +48 -0
- googleclient/auth/Google_LoginTicket.php +63 -0
- googleclient/auth/Google_OAuth2.php +453 -0
- googleclient/auth/Google_P12Signer.php +70 -0
- googleclient/auth/Google_PemVerifier.php +66 -0
- googleclient/auth/Google_Signer.php +30 -0
- googleclient/auth/Google_Verifier.php +31 -0
- googleclient/cache/Google_ApcCache.php +98 -0
- googleclient/cache/Google_Cache.php +55 -0
- googleclient/cache/Google_FileCache.php +137 -0
- googleclient/cache/Google_MemcacheCache.php +130 -0
- googleclient/config.php +81 -0
- googleclient/contrib/Google_AdExchangeSellerService.php +1262 -0
- googleclient/contrib/Google_AdSenseService.php +2054 -0
- googleclient/contrib/Google_AdexchangebuyerService.php +705 -0
- googleclient/contrib/Google_AdsensehostService.php +1376 -0
- googleclient/contrib/Google_AnalyticsService.php +4336 -0
- googleclient/contrib/Google_AndroidpublisherService.php +198 -0
- googleclient/contrib/Google_AppstateService.php +253 -0
- googleclient/contrib/Google_AuditService.php +274 -0
- googleclient/contrib/Google_BigqueryService.php +2011 -0
- googleclient/contrib/Google_BloggerService.php +1389 -0
- googleclient/contrib/Google_BooksService.php +3491 -0
- googleclient/contrib/Google_CalendarService.php +1971 -0
- googleclient/contrib/Google_CivicInfoService.php +778 -0
- googleclient/contrib/Google_ComputeService.php +4403 -0
- googleclient/contrib/Google_CoordinateService.php +700 -0
google_apps_login.php
ADDED
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Plugin Name: Google Apps Login
|
5 |
+
* Plugin URI: http://wp-glogin.com/
|
6 |
+
* Description: Easy login for your Wordpress users by using their Google accounts (uses OAuth2 and requires a Google Apps domain).
|
7 |
+
* Version: 1.0
|
8 |
+
* Author: Dan Lester
|
9 |
+
* Author URI: http://danlester.com/
|
10 |
+
* License: GPL3
|
11 |
+
*/
|
12 |
+
|
13 |
+
class google_apps_login {
|
14 |
+
|
15 |
+
function createGoogleClient() {
|
16 |
+
require_once 'googleclient/Google_Client.php';
|
17 |
+
require_once 'googleclient/contrib/Google_Oauth2Service.php';
|
18 |
+
|
19 |
+
$options = get_option('galogin');
|
20 |
+
|
21 |
+
$client = new Google_Client();
|
22 |
+
$client->setApplicationName("Wordpress Blog");
|
23 |
+
|
24 |
+
$client->setClientId($options['ga_clientid']);
|
25 |
+
$client->setClientSecret($options['ga_clientsecret']);
|
26 |
+
$client->setRedirectUri(wp_login_url());
|
27 |
+
|
28 |
+
$client->setScopes(Array('openid', 'email', 'https://www.googleapis.com/auth/userinfo.profile'));
|
29 |
+
$client->setApprovalPrompt('auto');
|
30 |
+
|
31 |
+
$oauthservice = new Google_Oauth2Service($client);
|
32 |
+
|
33 |
+
return Array($client, $oauthservice);
|
34 |
+
}
|
35 |
+
|
36 |
+
function ga_login_styles() { ?>
|
37 |
+
<style type="text/css">
|
38 |
+
form#loginform div.galogin {
|
39 |
+
float: right;
|
40 |
+
margin-top: 28px;
|
41 |
+
background: #DFDFDF;
|
42 |
+
text-align: center;
|
43 |
+
vertical-align: middle;
|
44 |
+
border-radius: 3px;
|
45 |
+
padding: 2px;
|
46 |
+
width: 58%;
|
47 |
+
height: 27px;
|
48 |
+
}
|
49 |
+
|
50 |
+
form#loginform div.galogin a {
|
51 |
+
color: #21759B;
|
52 |
+
position: relative;
|
53 |
+
top: 6px;
|
54 |
+
}
|
55 |
+
|
56 |
+
form#loginform div.galogin a:hover {
|
57 |
+
color: #278AB7;
|
58 |
+
}
|
59 |
+
|
60 |
+
.login .button-primary {
|
61 |
+
float: none;
|
62 |
+
margin-top: 10px;
|
63 |
+
}
|
64 |
+
</style>
|
65 |
+
<?php }
|
66 |
+
|
67 |
+
function ga_login_form() {
|
68 |
+
self::_ga_unset_session();
|
69 |
+
|
70 |
+
$clients = self::createGoogleClient();
|
71 |
+
$client = $clients[0];
|
72 |
+
|
73 |
+
// Generate a CSRF token
|
74 |
+
$state = md5(rand());
|
75 |
+
$_SESSION['galogin_state'] = $state;
|
76 |
+
$client->setState($state);
|
77 |
+
|
78 |
+
// Store following WP page if any
|
79 |
+
if (array_key_exists('redirect_to', $_REQUEST)) {
|
80 |
+
$_SESSION['galogin_redirect_to'] = $_REQUEST['redirect_to'];
|
81 |
+
}
|
82 |
+
|
83 |
+
$authUrl = $client->createAuthUrl();
|
84 |
+
?>
|
85 |
+
<div class="galogin">
|
86 |
+
<a href="<?php echo $authUrl; ?>">or <b>Login with Google</b></a>
|
87 |
+
</div>
|
88 |
+
<?php
|
89 |
+
}
|
90 |
+
|
91 |
+
function ga_authenticate($user) {
|
92 |
+
if (isset($_REQUEST['error'])) {
|
93 |
+
$user = new WP_Error('ga_login_error', $_REQUEST['error'] == 'access_denied' ? 'You did not grant access' : $_REQUEST['error']);
|
94 |
+
return self::displayAndReturnError($user);
|
95 |
+
}
|
96 |
+
|
97 |
+
$clients = self::createGoogleClient();
|
98 |
+
$client = $clients[0];
|
99 |
+
$oauthservice = $clients[1];
|
100 |
+
|
101 |
+
if (isset($_GET['code'])) {
|
102 |
+
if (session_id() && (!isset($_REQUEST['state']) || !isset($_SESSION['galogin_state'])
|
103 |
+
|| $_REQUEST['state'] != $_SESSION['galogin_state'])) {
|
104 |
+
$user = new WP_Error('ga_login_error', "Session mismatch - try again, but there could be a problem setting cookies");
|
105 |
+
return self::displayAndReturnError($user);
|
106 |
+
}
|
107 |
+
|
108 |
+
try {
|
109 |
+
$client->authenticate($_GET['code']);
|
110 |
+
|
111 |
+
/* userinfo example:
|
112 |
+
"id": "115886881859296909934",
|
113 |
+
"email": "dan@danlester.com",
|
114 |
+
"verified_email": true,
|
115 |
+
"name": "Dan Lester",
|
116 |
+
"given_name": "Dan",
|
117 |
+
"family_name": "Lester",
|
118 |
+
"link": "https://plus.google.com/115886881859296909934",
|
119 |
+
"picture": "https://lh3.googleusercontent.com/-r4WThnaSX8o/AAAAAAAAAAI/AAAAAAAAABE/pEJQwH5wyqM/photo.jpg",
|
120 |
+
"gender": "male",
|
121 |
+
"locale": "en-GB",
|
122 |
+
"hd": "danlester.com"
|
123 |
+
*/
|
124 |
+
$userinfo = $oauthservice->userinfo->get();
|
125 |
+
if ($userinfo && is_array($userinfo) && array_key_exists('email', $userinfo)
|
126 |
+
&& array_key_exists('verified_email', $userinfo)) {
|
127 |
+
|
128 |
+
$google_email = $userinfo['email'];
|
129 |
+
$google_verified_email = $userinfo['verified_email'];
|
130 |
+
|
131 |
+
if (!$google_verified_email) {
|
132 |
+
$user = new WP_Error('ga_login_error', 'Email needs to be verified on your Google Account');
|
133 |
+
}
|
134 |
+
else {
|
135 |
+
$user = get_user_by('email', $google_email);
|
136 |
+
|
137 |
+
if (!$user) {
|
138 |
+
$user = new WP_Error('ga_login_error', 'User '.$google_email.' not registered in Wordpress');
|
139 |
+
}
|
140 |
+
else {
|
141 |
+
if (session_id() && array_key_exists('galogin_redirect_to', $_SESSION)) {
|
142 |
+
$_SESSION['galogin_do_redirect_to'] = $_SESSION['galogin_redirect_to'];
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
147 |
+
else {
|
148 |
+
$user = new WP_Error('ga_login_error', "User authenticated OK, but error fetching user details from Google");
|
149 |
+
}
|
150 |
+
} catch (Google_Exception $e) {
|
151 |
+
$user = new WP_Error('ga_login_error', $e->getMessage());
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
// Tidy things up for next time
|
156 |
+
self::_ga_unset_session();
|
157 |
+
|
158 |
+
if (is_wp_error($user)) {
|
159 |
+
self::displayAndReturnError($user);
|
160 |
+
}
|
161 |
+
|
162 |
+
return $user;
|
163 |
+
}
|
164 |
+
|
165 |
+
function displayAndReturnError($user) {
|
166 |
+
if (is_wp_error($user) && get_bloginfo('version') < 3.7) {
|
167 |
+
// Only newer wordpress versions display errors from $user for us
|
168 |
+
global $error;
|
169 |
+
$error = htmlentities2($user->get_error_message());
|
170 |
+
}
|
171 |
+
return $user;
|
172 |
+
}
|
173 |
+
|
174 |
+
function ga_init() {
|
175 |
+
if(!session_id()) {
|
176 |
+
@session_start();
|
177 |
+
}
|
178 |
+
if (array_key_exists('galogin_do_redirect_to', $_SESSION)) {
|
179 |
+
// Login page originally contained a redirect url, so go there now all auth is finished
|
180 |
+
$url = $_SESSION['galogin_do_redirect_to'];
|
181 |
+
unset($_SESSION['galogin_do_redirect_to']);
|
182 |
+
wp_redirect($url);
|
183 |
+
exit;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
function _ga_unset_session() {
|
188 |
+
// Reset session state
|
189 |
+
if (session_id()) {
|
190 |
+
if (array_key_exists('galogin_redirect_to', $_SESSION)) {
|
191 |
+
unset($_SESSION['galogin_redirect_to']);
|
192 |
+
}
|
193 |
+
if (array_key_exists('galogin_state', $_SESSION)) {
|
194 |
+
unset($_SESSION['galogin_state']);
|
195 |
+
unset($_SESSION['state']);
|
196 |
+
}
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
function ga_admin_init() {
|
201 |
+
|
202 |
+
register_setting( 'galogin_options', 'galogin', Array('google_apps_login', 'ga_options_validate') );
|
203 |
+
|
204 |
+
add_settings_section('galogin_main_section', 'Main Settings',
|
205 |
+
array('google_apps_login', 'ga_section_text'), 'galogin');
|
206 |
+
|
207 |
+
add_settings_field('ga_clientid', 'Client ID',
|
208 |
+
array('google_apps_login', 'ga_do_settings_clientid'), 'galogin', 'galogin_main_section');
|
209 |
+
add_settings_field('ga_clientsecret', 'Client Secret',
|
210 |
+
array('google_apps_login', 'ga_do_settings_clientsecret'), 'galogin', 'galogin_main_section');
|
211 |
+
}
|
212 |
+
|
213 |
+
function ga_admin_menu() {
|
214 |
+
add_options_page('Google Apps Login settings', 'Google Apps Login',
|
215 |
+
'manage_options', 'galogin_list_options',
|
216 |
+
array('google_apps_login', 'ga_options_do_page'));
|
217 |
+
}
|
218 |
+
|
219 |
+
function ga_options_do_page() { ?>
|
220 |
+
<div>
|
221 |
+
<h2>Google Apps Login setup</h2>
|
222 |
+
Set up your blog to enable Google logins.
|
223 |
+
<form action="options.php" method="post">
|
224 |
+
<?php settings_fields('galogin_options'); ?>
|
225 |
+
<?php do_settings_sections('galogin'); ?>
|
226 |
+
|
227 |
+
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
|
228 |
+
</form></div> <?php
|
229 |
+
}
|
230 |
+
|
231 |
+
function ga_do_settings_clientid() {
|
232 |
+
$options = get_option('galogin');
|
233 |
+
echo "<input id='plugin_text_string' name='galogin[ga_clientid]' size='80' type='text' value='{$options['ga_clientid']}' />";
|
234 |
+
echo "<br /><span>Normally something like 1234567890123.apps.googleusercontent.com</span>";
|
235 |
+
}
|
236 |
+
|
237 |
+
function ga_do_settings_clientsecret() {
|
238 |
+
$options = get_option('galogin');
|
239 |
+
echo "<input id='plugin_text_string' name='galogin[ga_clientsecret]' size='40' type='text' value='{$options['ga_clientsecret']}' />";
|
240 |
+
echo "<br /><span>Normally something like sHSfR4_jf_2jsy-kjPjgf2dT</span>";
|
241 |
+
}
|
242 |
+
|
243 |
+
function ga_section_text() {
|
244 |
+
?>
|
245 |
+
<p>The Google Apps domain admin needs to go to
|
246 |
+
<a href="https://cloud.google.com/console" target="_blank">https://cloud.google.com/console</a>. If you
|
247 |
+
are not the domain admin, you may still have permissions to use the console, so just try it. If you are
|
248 |
+
not using Google Apps, then just use your regular Gmail account to access the console.
|
249 |
+
</p>
|
250 |
+
<p>There, create a new project (any name is fine, and just leave Project ID as it is) - you may be required to
|
251 |
+
accept a verification phone call or SMS from Google.</p>
|
252 |
+
|
253 |
+
<p>Then create a Web application within the project. To create the application,
|
254 |
+
you need to click into the new project, then click <i>APIs & Auth</i> in the left-hand menu.
|
255 |
+
Click <i>Registered Apps</i> beneath that, then click the red <i>Register App</i> button.
|
256 |
+
You can choose any name you wish, and make sure you select <i>Web Application</i> as the Platform type.
|
257 |
+
</p>
|
258 |
+
<p>
|
259 |
+
Once you have created the application, you may need to open up the <i>OAuth 2.0 Client ID</i> section to be able to complete
|
260 |
+
the following steps.
|
261 |
+
</p>
|
262 |
+
<p>You must input, into your new Google application, the following items:
|
263 |
+
<ul style="margin-left: 10px;">
|
264 |
+
<li>Web Origin: <?php echo site_url(); ?></li>
|
265 |
+
<li>Redirect URL: <?php echo wp_login_url(); ?></li>
|
266 |
+
<?php
|
267 |
+
if (force_ssl_login() && strtolower(substr(wp_login_url(),0,7)) == 'http://') {
|
268 |
+
?>
|
269 |
+
<li>
|
270 |
+
Redirect URL (add a 2nd entry): https://<?php echo substr(wp_login_url(),7); ?>
|
271 |
+
</li>
|
272 |
+
<?php
|
273 |
+
}
|
274 |
+
?>
|
275 |
+
</ul>
|
276 |
+
</p>
|
277 |
+
<p>Click Generate. You will see a Client ID and Client Secret which you must copy
|
278 |
+
and paste into the boxes below on this screen - i.e. back in your Wordpress admin, right here.</p>
|
279 |
+
|
280 |
+
<p><b>Optional:</b> In the Google Cloud Console, you can configure some things your users will see when they
|
281 |
+
login. By default, Google will tell them they are authorizing 'Project Default Service Account', which is
|
282 |
+
not very user friendly. You can change this to your company or blog name (and add your logo etc) by clicking
|
283 |
+
<i>Consent screen</i> (which is another sub-menu of <i>APIs & Auth</i>).
|
284 |
+
</p>
|
285 |
+
|
286 |
+
<p><b>For support and premium features, please visit: <a href="http://wp-glogin.com/" target="_blank">http://wp-glogin.com/</a></b></p>
|
287 |
+
|
288 |
+
<?php
|
289 |
+
}
|
290 |
+
|
291 |
+
function ga_options_validate($input) {
|
292 |
+
$newinput = Array();
|
293 |
+
$newinput['ga_clientid'] = trim($input['ga_clientid']);
|
294 |
+
$newinput['ga_clientsecret'] = trim($input['ga_clientsecret']);
|
295 |
+
if(!preg_match('/^.{10}.*$/i', $newinput['ga_clientid'])) {
|
296 |
+
add_settings_error(
|
297 |
+
'ga_clientid',
|
298 |
+
'tooshort_texterror',
|
299 |
+
'The Client ID should be longer than that',
|
300 |
+
'error'
|
301 |
+
);
|
302 |
+
}
|
303 |
+
if(!preg_match('/^.{10}.*$/i', $newinput['ga_clientsecret'])) {
|
304 |
+
add_settings_error(
|
305 |
+
'ga_clientsecret',
|
306 |
+
'tooshort_texterror',
|
307 |
+
'The Client Secret should be longer than that',
|
308 |
+
'error'
|
309 |
+
);
|
310 |
+
}
|
311 |
+
return $newinput;
|
312 |
+
}
|
313 |
+
|
314 |
+
function ga_on_uninstall() {
|
315 |
+
if (!current_user_can('activate_plugins'))
|
316 |
+
return;
|
317 |
+
|
318 |
+
// Important: Check if the file is the one
|
319 |
+
// that was registered during the uninstall hook.
|
320 |
+
if (!defined( 'WP_UNINSTALL_PLUGIN' ) || __FILE__ != WP_UNINSTALL_PLUGIN)
|
321 |
+
return;
|
322 |
+
|
323 |
+
// Remove options for plugin
|
324 |
+
delete_option('galogin');
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
add_action('login_enqueue_scripts', array('google_apps_login', 'ga_login_styles'));
|
329 |
+
add_action('login_form', array('google_apps_login', 'ga_login_form'));
|
330 |
+
add_action('authenticate', array('google_apps_login', 'ga_authenticate'));
|
331 |
+
add_action('init', array('google_apps_login', 'ga_init'), 1);
|
332 |
+
|
333 |
+
add_action('admin_init', array('google_apps_login', 'ga_admin_init'));
|
334 |
+
add_action('admin_menu', array('google_apps_login', 'ga_admin_menu'));
|
335 |
+
|
336 |
+
register_uninstall_hook(__FILE__, array('google_apps_login', 'ga_on_uninstall'));
|
337 |
+
|
338 |
+
?>
|
googleclient/Google_Client.php
ADDED
@@ -0,0 +1,471 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright 2010 Google Inc.
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
* you may not use this file except in compliance with the License.
|
7 |
+
* You may obtain a copy of the License at
|
8 |
+
*
|
9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
*
|
11 |
+
* Unless required by applicable law or agreed to in writing, software
|
12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
* See the License for the specific language governing permissions and
|
15 |
+
* limitations under the License.
|
16 |
+
*/
|
17 |
+
|
18 |
+
// Check for the json extension, the Google APIs PHP Client won't function
|
19 |
+
// without it.
|
20 |
+
if (! function_exists('json_decode')) {
|
21 |
+
throw new Exception('Google PHP API Client requires the JSON PHP extension');
|
22 |
+
}
|
23 |
+
|
24 |
+
if (! function_exists('http_build_query')) {
|
25 |
+
throw new Exception('Google PHP API Client requires http_build_query()');
|
26 |
+
}
|
27 |
+
|
28 |
+
if (! ini_get('date.timezone') && function_exists('date_default_timezone_set')) {
|
29 |
+
date_default_timezone_set('UTC');
|
30 |
+
}
|
31 |
+
|
32 |
+
// hack around with the include paths a bit so the library 'just works'
|
33 |
+
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
|
34 |
+
|
35 |
+
require_once "config.php";
|
36 |
+
// If a local configuration file is found, merge it's values with the default configuration
|
37 |
+
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
|
38 |
+
$defaultConfig = $apiConfig;
|
39 |
+
require_once (dirname(__FILE__) . '/local_config.php');
|
40 |
+
$apiConfig = array_merge($defaultConfig, $apiConfig);
|
41 |
+
}
|
42 |
+
|
43 |
+
// Include the top level classes, they each include their own dependencies
|
44 |
+
require_once 'service/Google_Model.php';
|
45 |
+
require_once 'service/Google_Service.php';
|
46 |
+
require_once 'service/Google_ServiceResource.php';
|
47 |
+
require_once 'auth/Google_AssertionCredentials.php';
|
48 |
+
require_once 'auth/Google_Signer.php';
|
49 |
+
require_once 'auth/Google_P12Signer.php';
|
50 |
+
require_once 'service/Google_BatchRequest.php';
|
51 |
+
require_once 'external/URITemplateParser.php';
|
52 |
+
require_once 'auth/Google_Auth.php';
|
53 |
+
require_once 'cache/Google_Cache.php';
|
54 |
+
require_once 'io/Google_IO.php';
|
55 |
+
require_once('service/Google_MediaFileUpload.php');
|
56 |
+
|
57 |
+
/**
|
58 |
+
* The Google API Client
|
59 |
+
* http://code.google.com/p/google-api-php-client/
|
60 |
+
*
|
61 |
+
* @author Chris Chabot <chabotc@google.com>
|
62 |
+
* @author Chirag Shah <chirags@google.com>
|
63 |
+
*/
|
64 |
+
class Google_Client {
|
65 |
+
/**
|
66 |
+
* @static
|
67 |
+
* @var Google_Auth $auth
|
68 |
+
*/
|
69 |
+
static $auth;
|
70 |
+
|
71 |
+
/**
|
72 |
+
* @static
|
73 |
+
* @var Google_IO $io
|
74 |
+
*/
|
75 |
+
static $io;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @static
|
79 |
+
* @var Google_Cache $cache
|
80 |
+
*/
|
81 |
+
static $cache;
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @static
|
85 |
+
* @var boolean $useBatch
|
86 |
+
*/
|
87 |
+
static $useBatch = false;
|
88 |
+
|
89 |
+
/** @var array $scopes */
|
90 |
+
protected $scopes = array();
|
91 |
+
|
92 |
+
/** @var bool $useObjects */
|
93 |
+
protected $useObjects = false;
|
94 |
+
|
95 |
+
// definitions of services that are discovered.
|
96 |
+
protected $services = array();
|
97 |
+
|
98 |
+
// Used to track authenticated state, can't discover services after doing authenticate()
|
99 |
+
private $authenticated = false;
|
100 |
+
|
101 |
+
public function __construct($config = array()) {
|
102 |
+
global $apiConfig;
|
103 |
+
$apiConfig = array_merge($apiConfig, $config);
|
104 |
+
self::$cache = new $apiConfig['cacheClass']();
|
105 |
+
self::$auth = new $apiConfig['authClass']();
|
106 |
+
self::$io = new $apiConfig['ioClass']();
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Add a service
|
111 |
+
*/
|
112 |
+
public function addService($service, $version = false) {
|
113 |
+
global $apiConfig;
|
114 |
+
if ($this->authenticated) {
|
115 |
+
throw new Google_Exception('Cant add services after having authenticated');
|
116 |
+
}
|
117 |
+
$this->services[$service] = array();
|
118 |
+
if (isset($apiConfig['services'][$service])) {
|
119 |
+
// Merge the service descriptor with the default values
|
120 |
+
$this->services[$service] = array_merge($this->services[$service], $apiConfig['services'][$service]);
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
public function authenticate($code = null) {
|
125 |
+
$service = $this->prepareService();
|
126 |
+
$this->authenticated = true;
|
127 |
+
return self::$auth->authenticate($service, $code);
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* @return array
|
132 |
+
* @visible For Testing
|
133 |
+
*/
|
134 |
+
public function prepareService() {
|
135 |
+
$service = array();
|
136 |
+
$scopes = array();
|
137 |
+
if ($this->scopes) {
|
138 |
+
$scopes = $this->scopes;
|
139 |
+
} else {
|
140 |
+
foreach ($this->services as $key => $val) {
|
141 |
+
if (isset($val['scope'])) {
|
142 |
+
if (is_array($val['scope'])) {
|
143 |
+
$scopes = array_merge($val['scope'], $scopes);
|
144 |
+
} else {
|
145 |
+
$scopes[] = $val['scope'];
|
146 |
+
}
|
147 |
+
} else {
|
148 |
+
$scopes[] = 'https://www.googleapis.com/auth/' . $key;
|
149 |
+
}
|
150 |
+
unset($val['discoveryURI']);
|
151 |
+
unset($val['scope']);
|
152 |
+
$service = array_merge($service, $val);
|
153 |
+
}
|
154 |
+
}
|
155 |
+
$service['scope'] = implode(' ', $scopes);
|
156 |
+
return $service;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Set the OAuth 2.0 access token using the string that resulted from calling authenticate()
|
161 |
+
* or Google_Client#getAccessToken().
|
162 |
+
* @param string $accessToken JSON encoded string containing in the following format:
|
163 |
+
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
164 |
+
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
|
165 |
+
*/
|
166 |
+
public function setAccessToken($accessToken) {
|
167 |
+
if ($accessToken == null || 'null' == $accessToken) {
|
168 |
+
$accessToken = null;
|
169 |
+
}
|
170 |
+
self::$auth->setAccessToken($accessToken);
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Set the type of Auth class the client should use.
|
175 |
+
* @param string $authClassName
|
176 |
+
*/
|
177 |
+
public function setAuthClass($authClassName) {
|
178 |
+
self::$auth = new $authClassName();
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Construct the OAuth 2.0 authorization request URI.
|
183 |
+
* @return string
|
184 |
+
*/
|
185 |
+
public function createAuthUrl() {
|
186 |
+
$service = $this->prepareService();
|
187 |
+
return self::$auth->createAuthUrl($service['scope']);
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Get the OAuth 2.0 access token.
|
192 |
+
* @return string $accessToken JSON encoded string in the following format:
|
193 |
+
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
194 |
+
* "expires_in":3600,"id_token":"TOKEN", "created":1320790426}
|
195 |
+
*/
|
196 |
+
public function getAccessToken() {
|
197 |
+
$token = self::$auth->getAccessToken();
|
198 |
+
return (null == $token || 'null' == $token) ? null : $token;
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Returns if the access_token is expired.
|
203 |
+
* @return bool Returns True if the access_token is expired.
|
204 |
+
*/
|
205 |
+
public function isAccessTokenExpired() {
|
206 |
+
return self::$auth->isAccessTokenExpired();
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Set the developer key to use, these are obtained through the API Console.
|
211 |
+
* @see http://code.google.com/apis/console-help/#generatingdevkeys
|
212 |
+
* @param string $developerKey
|
213 |
+
*/
|
214 |
+
public function setDeveloperKey($developerKey) {
|
215 |
+
self::$auth->setDeveloperKey($developerKey);
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Set OAuth 2.0 "state" parameter to achieve per-request customization.
|
220 |
+
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-3.1.2.2
|
221 |
+
* @param string $state
|
222 |
+
*/
|
223 |
+
public function setState($state) {
|
224 |
+
self::$auth->setState($state);
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* @param string $accessType Possible values for access_type include:
|
229 |
+
* {@code "offline"} to request offline access from the user. (This is the default value)
|
230 |
+
* {@code "online"} to request online access from the user.
|
231 |
+
*/
|
232 |
+
public function setAccessType($accessType) {
|
233 |
+
self::$auth->setAccessType($accessType);
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* @param string $approvalPrompt Possible values for approval_prompt include:
|
238 |
+
* {@code "force"} to force the approval UI to appear. (This is the default value)
|
239 |
+
* {@code "auto"} to request auto-approval when possible.
|
240 |
+
*/
|
241 |
+
public function setApprovalPrompt($approvalPrompt) {
|
242 |
+
self::$auth->setApprovalPrompt($approvalPrompt);
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Set the application name, this is included in the User-Agent HTTP header.
|
247 |
+
* @param string $applicationName
|
248 |
+
*/
|
249 |
+
public function setApplicationName($applicationName) {
|
250 |
+
global $apiConfig;
|
251 |
+
$apiConfig['application_name'] = $applicationName;
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Set the OAuth 2.0 Client ID.
|
256 |
+
* @param string $clientId
|
257 |
+
*/
|
258 |
+
public function setClientId($clientId) {
|
259 |
+
global $apiConfig;
|
260 |
+
$apiConfig['oauth2_client_id'] = $clientId;
|
261 |
+
self::$auth->clientId = $clientId;
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* Get the OAuth 2.0 Client ID.
|
266 |
+
*/
|
267 |
+
public function getClientId() {
|
268 |
+
return self::$auth->clientId;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Set the OAuth 2.0 Client Secret.
|
273 |
+
* @param string $clientSecret
|
274 |
+
*/
|
275 |
+
public function setClientSecret($clientSecret) {
|
276 |
+
global $apiConfig;
|
277 |
+
$apiConfig['oauth2_client_secret'] = $clientSecret;
|
278 |
+
self::$auth->clientSecret = $clientSecret;
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Get the OAuth 2.0 Client Secret.
|
283 |
+
*/
|
284 |
+
public function getClientSecret() {
|
285 |
+
return self::$auth->clientSecret;
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Set the OAuth 2.0 Redirect URI.
|
290 |
+
* @param string $redirectUri
|
291 |
+
*/
|
292 |
+
public function setRedirectUri($redirectUri) {
|
293 |
+
global $apiConfig;
|
294 |
+
$apiConfig['oauth2_redirect_uri'] = $redirectUri;
|
295 |
+
self::$auth->redirectUri = $redirectUri;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Get the OAuth 2.0 Redirect URI.
|
300 |
+
*/
|
301 |
+
public function getRedirectUri() {
|
302 |
+
return self::$auth->redirectUri;
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Fetches a fresh OAuth 2.0 access token with the given refresh token.
|
307 |
+
* @param string $refreshToken
|
308 |
+
* @return void
|
309 |
+
*/
|
310 |
+
public function refreshToken($refreshToken) {
|
311 |
+
self::$auth->refreshToken($refreshToken);
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
316 |
+
* token, if a token isn't provided.
|
317 |
+
* @throws Google_AuthException
|
318 |
+
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
319 |
+
* @return boolean Returns True if the revocation was successful, otherwise False.
|
320 |
+
*/
|
321 |
+
public function revokeToken($token = null) {
|
322 |
+
self::$auth->revokeToken($token);
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Verify an id_token. This method will verify the current id_token, if one
|
327 |
+
* isn't provided.
|
328 |
+
* @throws Google_AuthException
|
329 |
+
* @param string|null $token The token (id_token) that should be verified.
|
330 |
+
* @return Google_LoginTicket Returns an apiLoginTicket if the verification was
|
331 |
+
* successful.
|
332 |
+
*/
|
333 |
+
public function verifyIdToken($token = null) {
|
334 |
+
return self::$auth->verifyIdToken($token);
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* @param Google_AssertionCredentials $creds
|
339 |
+
* @return void
|
340 |
+
*/
|
341 |
+
public function setAssertionCredentials(Google_AssertionCredentials $creds) {
|
342 |
+
self::$auth->setAssertionCredentials($creds);
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* This function allows you to overrule the automatically generated scopes,
|
347 |
+
* so that you can ask for more or less permission in the auth flow
|
348 |
+
* Set this before you call authenticate() though!
|
349 |
+
* @param array $scopes, ie: array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/moderator')
|
350 |
+
*/
|
351 |
+
public function setScopes($scopes) {
|
352 |
+
$this->scopes = is_string($scopes) ? explode(" ", $scopes) : $scopes;
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Returns the list of scopes set on the client
|
357 |
+
* @return array the list of scopes
|
358 |
+
*
|
359 |
+
*/
|
360 |
+
public function getScopes() {
|
361 |
+
return $this->scopes;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* If 'plus.login' is included in the list of requested scopes, you can use
|
366 |
+
* this method to define types of app activities that your app will write.
|
367 |
+
* You can find a list of available types here:
|
368 |
+
* @link https://developers.google.com/+/api/moment-types
|
369 |
+
*
|
370 |
+
* @param array $requestVisibleActions Array of app activity types
|
371 |
+
*/
|
372 |
+
public function setRequestVisibleActions($requestVisibleActions) {
|
373 |
+
self::$auth->requestVisibleActions =
|
374 |
+
join(" ", $requestVisibleActions);
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Declare if objects should be returned by the api service classes.
|
379 |
+
*
|
380 |
+
* @param boolean $useObjects True if objects should be returned by the service classes.
|
381 |
+
* False if associative arrays should be returned (default behavior).
|
382 |
+
* @experimental
|
383 |
+
*/
|
384 |
+
public function setUseObjects($useObjects) {
|
385 |
+
global $apiConfig;
|
386 |
+
$apiConfig['use_objects'] = $useObjects;
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Declare if objects should be returned by the api service classes.
|
391 |
+
*
|
392 |
+
* @param boolean $useBatch True if the experimental batch support should
|
393 |
+
* be enabled. Defaults to False.
|
394 |
+
* @experimental
|
395 |
+
*/
|
396 |
+
public function setUseBatch($useBatch) {
|
397 |
+
self::$useBatch = $useBatch;
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* @static
|
402 |
+
* @return Google_Auth the implementation of apiAuth.
|
403 |
+
*/
|
404 |
+
public static function getAuth() {
|
405 |
+
return Google_Client::$auth;
|
406 |
+
}
|
407 |
+
|
408 |
+
/**
|
409 |
+
* @static
|
410 |
+
* @return Google_IO the implementation of apiIo.
|
411 |
+
*/
|
412 |
+
public static function getIo() {
|
413 |
+
return Google_Client::$io;
|
414 |
+
}
|
415 |
+
|
416 |
+
/**
|
417 |
+
* @return Google_Cache the implementation of apiCache.
|
418 |
+
*/
|
419 |
+
public function getCache() {
|
420 |
+
return Google_Client::$cache;
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
// Exceptions that the Google PHP API Library can throw
|
425 |
+
class Google_Exception extends Exception {}
|
426 |
+
class Google_AuthException extends Google_Exception {}
|
427 |
+
class Google_CacheException extends Google_Exception {}
|
428 |
+
class Google_IOException extends Google_Exception {}
|
429 |
+
class Google_ServiceException extends Google_Exception {
|
430 |
+
/**
|
431 |
+
* Optional list of errors returned in a JSON body of an HTTP error response.
|
432 |
+
*/
|
433 |
+
protected $errors = array();
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Override default constructor to add ability to set $errors.
|
437 |
+
*
|
438 |
+
* @param string $message
|
439 |
+
* @param int $code
|
440 |
+
* @param Exception|null $previous
|
441 |
+
* @param [{string, string}] errors List of errors returned in an HTTP
|
442 |
+
* response. Defaults to [].
|
443 |
+
*/
|
444 |
+
public function __construct($message, $code = 0, Exception $previous = null,
|
445 |
+
$errors = array()) {
|
446 |
+
if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
447 |
+
parent::__construct($message, $code, $previous);
|
448 |
+
} else {
|
449 |
+
parent::__construct($message, $code);
|
450 |
+
}
|
451 |
+
|
452 |
+
$this->errors = $errors;
|
453 |
+
}
|
454 |
+
|
455 |
+
/**
|
456 |
+
* An example of the possible errors returned.
|
457 |
+
*
|
458 |
+
* {
|
459 |
+
* "domain": "global",
|
460 |
+
* "reason": "authError",
|
461 |
+
* "message": "Invalid Credentials",
|
462 |
+
* "locationType": "header",
|
463 |
+
* "location": "Authorization",
|
464 |
+
* }
|
465 |
+
*
|
466 |
+
* @return [{string, string}] List of errors return in an HTTP response or [].
|
467 |
+
*/
|
468 |
+
public function getErrors() {
|
469 |
+
return $this->errors;
|
470 |
+
}
|
471 |
+
}
|
googleclient/LICENSE
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
202 |
+
|
203 |
+
|
googleclient/NOTICE
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
This product contains the following libraries:
|
2 |
+
|
3 |
+
XRDS-Simple library from http://code.google.com/p/diso/
|
4 |
+
Apache License 2.0
|
googleclient/README
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Google APIs Client Library for PHP
|
2 |
+
=====================================
|
3 |
+
|
4 |
+
== Description
|
5 |
+
The Google API Client Library enables you to work with Google APIs such as Google+, Drive, Tasks, or Latitude on your server.
|
6 |
+
|
7 |
+
Requirements:
|
8 |
+
PHP 5.2.x or higher [http://www.php.net/]
|
9 |
+
PHP Curl extension [http://www.php.net/manual/en/intro.curl.php]
|
10 |
+
PHP JSON extension [http://php.net/manual/en/book.json.php]
|
11 |
+
|
12 |
+
Project page:
|
13 |
+
http://code.google.com/p/google-api-php-client
|
14 |
+
|
15 |
+
OAuth 2 instructions:
|
16 |
+
http://code.google.com/p/google-api-php-client/wiki/OAuth2
|
17 |
+
|
18 |
+
Report a defect or feature request here:
|
19 |
+
http://code.google.com/p/google-api-php-client/issues/entry
|
20 |
+
|
21 |
+
Subscribe to project updates in your feed reader:
|
22 |
+
http://code.google.com/feeds/p/google-api-php-client/updates/basic
|
23 |
+
|
24 |
+
Supported sample applications:
|
25 |
+
http://code.google.com/p/google-api-php-client/wiki/Samples
|
26 |
+
|
27 |
+
== Basic Example
|
28 |
+
<?php
|
29 |
+
require_once 'path/to/src/Google_Client.php';
|
30 |
+
require_once 'path/to/src/contrib/apiBooksService.php';
|
31 |
+
|
32 |
+
$client = new Google_Client();
|
33 |
+
$service = new Google_BooksService($client);
|
34 |
+
|
35 |
+
$optParams = array('filter' => 'free-ebooks');
|
36 |
+
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
|
37 |
+
|
38 |
+
foreach ($results['items'] as $item) {
|
39 |
+
print($item['volumeInfo']['title'] . '<br>');
|
40 |
+
}
|
googleclient/auth/Google_AssertionCredentials.php
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright 2012 Google Inc.
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
* you may not use this file except in compliance with the License.
|
7 |
+
* You may obtain a copy of the License at
|
8 |
+
*
|
9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
*
|
11 |
+
* Unless required by applicable law or agreed to in writing, software
|
12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
* See the License for the specific language governing permissions and
|
15 |
+
* limitations under the License.
|
16 |
+
*/
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Credentials object used for OAuth 2.0 Signed JWT assertion grants.
|
20 |
+
*
|
21 |
+
* @author Chirag Shah <chirags@google.com>
|
22 |
+
*/
|
23 |
+
class Google_AssertionCredentials {
|
24 |
+
const MAX_TOKEN_LIFETIME_SECS = 3600;
|
25 |
+
|
26 |
+
public $serviceAccountName;
|
27 |
+
public $scopes;
|
28 |
+
public $privateKey;
|
29 |
+
public $privateKeyPassword;
|
30 |
+
public $assertionType;
|
31 |
+
public $sub;
|
32 |
+
/**
|
33 |
+
* @deprecated
|
34 |
+
* @link http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
|
35 |
+
*/
|
36 |
+
public $prn;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @param $serviceAccountName
|
40 |
+
* @param $scopes array List of scopes
|
41 |
+
* @param $privateKey
|
42 |
+
* @param string $privateKeyPassword
|
43 |
+
* @param string $assertionType
|
44 |
+
* @param bool|string $sub The email address of the user for which the
|
45 |
+
* application is requesting delegated access.
|
46 |
+
*/
|
47 |
+
public function __construct(
|
48 |
+
$serviceAccountName,
|
49 |
+
$scopes,
|
50 |
+
$privateKey,
|
51 |
+
$privateKeyPassword = 'notasecret',
|
52 |
+
$assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer',
|
53 |
+
$sub = false) {
|
54 |
+
$this->serviceAccountName = $serviceAccountName;
|
55 |
+
$this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes);
|
56 |
+
$this->privateKey = $privateKey;
|
57 |
+
$this->privateKeyPassword = $privateKeyPassword;
|
58 |
+
$this->assertionType = $assertionType;
|
59 |
+
$this->sub = $sub;
|
60 |
+
$this->prn = $sub;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function generateAssertion() {
|
64 |
+
$now = time();
|
65 |
+
|
66 |
+
$jwtParams = array(
|
67 |
+
'aud' => Google_OAuth2::OAUTH2_TOKEN_URI,
|
68 |
+
'scope' => $this->scopes,
|
69 |
+
'iat' => $now,
|
70 |
+
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
|
71 |
+
'iss' => $this->serviceAccountName,
|
72 |
+
);
|
73 |
+
|
74 |
+
if ($this->sub !== false) {
|
75 |
+
$jwtParams['sub'] = $this->sub;
|
76 |
+
} else if ($this->prn !== false) {
|
77 |
+
$jwtParams['prn'] = $this->prn;
|
78 |
+
}
|
79 |
+
|
80 |
+
return $this->makeSignedJwt($jwtParams);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Creates a signed JWT.
|
85 |
+
* @param array $payload
|
86 |
+
* @return string The signed JWT.
|
87 |
+
*/
|
88 |
+
private function makeSignedJwt($payload) {
|
89 |
+
$header = array('typ' => 'JWT', 'alg' => 'RS256');
|
90 |
+
|
91 |
+
$segments = array(
|
92 |
+
Google_Utils::urlSafeB64Encode(json_encode($header)),
|
93 |
+
Google_Utils::urlSafeB64Encode(json_encode($payload))
|
94 |
+
);
|
95 |
+
|
96 |
+
$signingInput = implode('.', $segments);
|
97 |
+
$signer = new Google_P12Signer($this->privateKey, $this->privateKeyPassword);
|
98 |
+
$signature = $signer->sign($signingInput);
|
99 |
+
$segments[] = Google_Utils::urlSafeB64Encode($signature);
|
100 |
+
|
101 |
+
return implode(".", $segments);
|
102 |
+
}
|
103 |
+
}
|
googleclient/auth/Google_Auth.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright 2010 Google Inc.
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
* you may not use this file except in compliance with the License.
|
7 |
+
* You may obtain a copy of the License at
|
8 |
+
*
|
9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
*
|
11 |
+
* Unless required by applicable law or agreed to in writing, software
|
12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
* See the License for the specific language governing permissions and
|
15 |
+
* limitations under the License.
|
16 |
+
*/
|
17 |
+
|
18 |
+
require_once "Google_AuthNone.php";
|
19 |
+
require_once "Google_OAuth2.php";
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Abstract class for the Authentication in the API client
|
23 |
+
* @author Chris Chabot <chabotc@google.com>
|
24 |
+
*
|
25 |
+
*/
|
26 |
+
abstract class Google_Auth {
|
27 |
+
abstract public function authenticate($service);
|
28 |
+
abstract public function sign(Google_HttpRequest $request);
|
29 |
+
abstract public function createAuthUrl($scope);
|
30 |
+
|
31 |
+
abstract public function getAccessToken();
|
32 |
+
abstract public function setAccessToken($accessToken);
|
33 |
+
abstract public function setDeveloperKey($developerKey);
|
34 |
+
abstract public function refreshToken($refreshToken);
|
35 |
+
abstract public function revokeToken();
|
36 |
+
}
|
googleclient/auth/Google_AuthNone.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright 2010 Google Inc.
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
* you may not use this file except in compliance with the License.
|
7 |
+
* You may obtain a copy of the License at
|
8 |
+
*
|
9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
*
|
11 |
+
* Unless required by applicable law or agreed to in writing, software
|
12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
* See the License for the specific language governing permissions and
|
15 |
+
* limitations under the License.
|
16 |
+
*/
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Do-nothing authentication implementation, use this if you want to make un-authenticated calls
|
20 |
+
* @author Chris Chabot <chabotc@google.com>
|
21 |
+
* @author Chirag Shah <chirags@google.com>
|
22 |
+
*/
|
23 |
+
class Google_AuthNone extends Google_Auth {
|
24 |
+
public $key = null;
|
25 |
+
|
26 |
+
public function __construct() {
|
27 |
+
global $apiConfig;
|
28 |
+
if (!empty($apiConfig['developer_key'])) {
|
29 |
+
$this->setDeveloperKey($apiConfig['developer_key']);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
public function setDeveloperKey($key) {$this->key = $key;}
|
34 |
+
public function authenticate($service) {/*noop*/}
|
35 |
+
public function setAccessToken($accessToken) {/* noop*/}
|
36 |
+
public function getAccessToken() {return null;}
|
37 |
+
public function createAuthUrl($scope) {return null;}
|
38 |
+
public function refreshToken($refreshToken) {/* noop*/}
|
39 |
+
public function revokeToken() {/* noop*/}
|
40 |
+
|
41 |
+
public function sign(Google_HttpRequest $request) {
|
42 |
+
if ($this->key) {
|
43 |
+
$request->setUrl($request->getUrl() . ((strpos($request->getUrl(), '?') === false) ? '?' : '&')
|
44 |
+
. 'key='.urlencode($this->key));
|
45 |
+
}
|
46 |
+
return $request;
|
47 |
+
}
|
48 |
+
}
|
googleclient/auth/Google_LoginTicket.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Copyright 2011 Google Inc.
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
* you may not use this file except in compliance with the License.
|
7 |
+
* You may obtain a copy of the License at
|
8 |
+
*
|
9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
*
|
11 |
+
* Unless required by applicable law or agreed to in writing, software
|
12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
* See the License for the specific language governing permissions and
|
15 |
+
* limitations under the License.
|
16 |
+
*/
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Class to hold information about an authenticated login.
|
20 |
+
*
|
21 |
+
* @author Brian Eaton <beaton@google.com>
|
22 |
+
*/
|
23 |
+
class Google_LoginTicket {
|
24 |
+
const USER_ATTR = "id";
|
25 |
+
|
26 |
+
// Information from id token envelope.
|
27 |
+
private $envelope;
|
28 |
+
|
29 |
+
// Information from id token payload.
|
30 |
+
private $payload;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Creates a user based on the supplied token.
|
34 |
+
*
|
35 |
+
* @param string $envelope Header from a verified authentication token.
|
36 |
+
* @param string $payload Information from a verified authentication token.
|
37 |
+
*/
|
38 |
+
public function __construct($envelope, $payload) {
|
39 |
+
$this->envelope = $envelope;
|
40 |
+
$this->payload = $payload;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Returns the numeric identifier for the user.
|
45 |
+
* @throws Google_AuthException
|
46 |
+
* @return
|
47 |
+
*/
|
48 |
+
public function getUserId() {
|
49 |
+
if (array_key_exists(self::USER_ATTR, $this->payload)) {
|
50 |
+
return $this->payload[self::USER_ATTR];
|
51 |
+
}
|
52 |
+
throw new Google_AuthException("No user_id in token");
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Returns attributes from the login ticket. This can contain
|
57 |
+
* various information about the user session.
|
58 |
+
* @return array
|
59 |
+
*/
|
60 |
+
public function getAttributes() {
|
61 |
+
return array("envelope" => $this->envelope, "payload" => $this->payload);
|
62 |
+
}
|
63 |
+
}
|
googleclient/auth/Google_OAuth2.php
ADDED
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|