My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 9 attachment: oauth2-php-1288457112.patch (20.8 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
diff -r 969fd139d13f lib/oauth.php
--- a/lib/oauth.php Sat Sep 04 11:43:41 2010 -0700
+++ b/lib/oauth.php Sun Oct 31 00:45:12 2010 +0800
@@ -1,7 +1,7 @@
<?php
/**
* http://code.google.com/p/oauth2-php/
- *
+ *
* By Tim Ridgely tim.ridgely@gmail.com
* Updated to draft v10 by Aaron Parecki aaron@parecki.com
*/
@@ -101,10 +101,10 @@
//
// Return null if the supplied token is invalid
//
- abstract protected function get_access_token($token_id);
+ abstract protected function get_access_token($oauth_token);

// Store the supplied values
- abstract protected function store_access_token($token_id, $client_id, $expires, $scope = null);
+ abstract protected function store_access_token($oauth_token, $client_id, $expires, $scope = null);

/*
*
@@ -271,7 +271,7 @@
}

private $old_refresh_token = '';
-
+
// Expire a used refresh token.
// This is not explicitly required in the spec, but is almost implied. After granting a new refresh token,
// the old one is no longer useful and so should be forcibly expired in the data store so it can't be used again.
@@ -280,9 +280,9 @@
// for any sort of success/failure, so you should bail out of the
// script and provide a descriptive fail message

- return;
+ return;
}
-
+
// Grant access tokens for the "none" grant type
// Not really described in the IETF Draft, so I just left a method stub...do whatever you want!
// Required for NONE_GRANT_TYPE
@@ -433,7 +433,7 @@
"grant_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_TOKEN_GRANT_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
"code" => array("flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"username" => array("flags" => FILTER_REQUIRE_SCALAR),
"password" => array("flags" => FILTER_REQUIRE_SCALAR),
"assertion_type" => array("flags" => FILTER_REQUIRE_SCALAR),
@@ -442,7 +442,7 @@
);

$input = filter_input_array(INPUT_POST, $filters);
-
+
// Grant Type must be specified.
if (!$input["grant_type"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_REQUEST, 'Invalid grant_type parameter or parameter missing');
@@ -503,13 +503,13 @@

if ($stored === null || $client[0] != $stored["client_id"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_GRANT);
-
+
if ($stored["expires"] < time())
$this->error(ERROR_BAD_REQUEST, ERROR_EXPIRED_TOKEN);

// store the refresh token locally so we can delete it when a new refresh token is generated
$this->old_refresh_token = $stored["token"];
-
+
break;
case NONE_GRANT_TYPE:
$stored = $this->check_none_access($client[0]);
@@ -562,7 +562,7 @@
$filters = array(
"client_id" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_CLIENT_ID), "flags" => FILTER_REQUIRE_SCALAR),
"response_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_AUTH_RESPONSE_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"state" => array("flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
);
@@ -684,7 +684,7 @@
$this->store_refresh_token($token["refresh_token"], $client_id, time() + $this->refresh_token_lifetime, $scope);
// If we've granted a new refresh token, expire the old one
if($this->old_refresh_token)
- $this->expire_refresh_token($this->old_refresh_token);
+ $this->expire_refresh_token($this->old_refresh_token);
}

return $token;
@@ -735,7 +735,7 @@
$this->send_json_headers();
$response = array("error" => $message);
if(ERROR_VERBOSE && $description)
- $response["error_description"] = $description;
+ $response["error_description"] = $description;
echo json_encode($response);
}

@@ -756,4 +756,4 @@

$this->do_redirect_uri_callback($redirect_uri, $result);
}
-}
\ No newline at end of file
+}
diff -r 969fd139d13f server/examples/mongo/lib/oauth.php
--- a/server/examples/mongo/lib/oauth.php Sat Sep 04 11:43:41 2010 -0700
+++ b/server/examples/mongo/lib/oauth.php Sun Oct 31 00:45:12 2010 +0800
@@ -1,7 +1,7 @@
<?php
/**
* http://code.google.com/p/oauth2-php/
- *
+ *
* By Tim Ridgely tim.ridgely@gmail.com
* Updated to draft v10 by Aaron Parecki aaron@parecki.com
*/
@@ -101,10 +101,10 @@
//
// Return null if the supplied token is invalid
//
- abstract protected function get_access_token($token_id);
+ abstract protected function get_access_token($oauth_token);

// Store the supplied values
- abstract protected function store_access_token($token_id, $client_id, $expires, $scope = null);
+ abstract protected function store_access_token($oauth_token, $client_id, $expires, $scope = null);

/*
*
@@ -271,7 +271,7 @@
}

private $old_refresh_token = '';
-
+
// Expire a used refresh token.
// This is not explicitly required in the spec, but is almost implied. After granting a new refresh token,
// the old one is no longer useful and so should be forcibly expired in the data store so it can't be used again.
@@ -280,9 +280,9 @@
// for any sort of success/failure, so you should bail out of the
// script and provide a descriptive fail message

- return;
+ return;
}
-
+
// Grant access tokens for the "none" grant type
// Not really described in the IETF Draft, so I just left a method stub...do whatever you want!
// Required for NONE_GRANT_TYPE
@@ -433,7 +433,7 @@
"grant_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_TOKEN_GRANT_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
"code" => array("flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"username" => array("flags" => FILTER_REQUIRE_SCALAR),
"password" => array("flags" => FILTER_REQUIRE_SCALAR),
"assertion_type" => array("flags" => FILTER_REQUIRE_SCALAR),
@@ -442,7 +442,7 @@
);

$input = filter_input_array(INPUT_POST, $filters);
-
+
// Grant Type must be specified.
if (!$input["grant_type"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_REQUEST, 'Invalid grant_type parameter or parameter missing');
@@ -503,13 +503,13 @@

if ($stored === null || $client[0] != $stored["client_id"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_GRANT);
-
+
if ($stored["expires"] < time())
$this->error(ERROR_BAD_REQUEST, ERROR_EXPIRED_TOKEN);

// store the refresh token locally so we can delete it when a new refresh token is generated
$this->old_refresh_token = $stored["token"];
-
+
break;
case NONE_GRANT_TYPE:
$stored = $this->check_none_access($client[0]);
@@ -562,7 +562,7 @@
$filters = array(
"client_id" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_CLIENT_ID), "flags" => FILTER_REQUIRE_SCALAR),
"response_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_AUTH_RESPONSE_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"state" => array("flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
);
@@ -684,7 +684,7 @@
$this->store_refresh_token($token["refresh_token"], $client_id, time() + $this->refresh_token_lifetime, $scope);
// If we've granted a new refresh token, expire the old one
if($this->old_refresh_token)
- $this->expire_refresh_token($this->old_refresh_token);
+ $this->expire_refresh_token($this->old_refresh_token);
}

return $token;
@@ -735,7 +735,7 @@
$this->send_json_headers();
$response = array("error" => $message);
if(ERROR_VERBOSE && $description)
- $response["error_description"] = $description;
+ $response["error_description"] = $description;
echo json_encode($response);
}

@@ -756,4 +756,4 @@

$this->do_redirect_uri_callback($redirect_uri, $result);
}
-}
\ No newline at end of file
+}
diff -r 969fd139d13f server/examples/pdo/lib/oauth.php
--- a/server/examples/pdo/lib/oauth.php Sat Sep 04 11:43:41 2010 -0700
+++ b/server/examples/pdo/lib/oauth.php Sun Oct 31 00:45:12 2010 +0800
@@ -1,7 +1,7 @@
<?php
/**
* http://code.google.com/p/oauth2-php/
- *
+ *
* By Tim Ridgely tim.ridgely@gmail.com
* Updated to draft v10 by Aaron Parecki aaron@parecki.com
*/
@@ -101,10 +101,10 @@
//
// Return null if the supplied token is invalid
//
- abstract protected function get_access_token($token_id);
+ abstract protected function get_access_token($oauth_token);

// Store the supplied values
- abstract protected function store_access_token($token_id, $client_id, $expires, $scope = null);
+ abstract protected function store_access_token($oauth_token, $client_id, $expires, $scope = null);

/*
*
@@ -271,7 +271,7 @@
}

private $old_refresh_token = '';
-
+
// Expire a used refresh token.
// This is not explicitly required in the spec, but is almost implied. After granting a new refresh token,
// the old one is no longer useful and so should be forcibly expired in the data store so it can't be used again.
@@ -280,9 +280,9 @@
// for any sort of success/failure, so you should bail out of the
// script and provide a descriptive fail message

- return;
+ return;
}
-
+
// Grant access tokens for the "none" grant type
// Not really described in the IETF Draft, so I just left a method stub...do whatever you want!
// Required for NONE_GRANT_TYPE
@@ -433,7 +433,7 @@
"grant_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_TOKEN_GRANT_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
"code" => array("flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"username" => array("flags" => FILTER_REQUIRE_SCALAR),
"password" => array("flags" => FILTER_REQUIRE_SCALAR),
"assertion_type" => array("flags" => FILTER_REQUIRE_SCALAR),
@@ -442,7 +442,7 @@
);

$input = filter_input_array(INPUT_POST, $filters);
-
+
// Grant Type must be specified.
if (!$input["grant_type"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_REQUEST, 'Invalid grant_type parameter or parameter missing');
@@ -503,13 +503,13 @@

if ($stored === null || $client[0] != $stored["client_id"])
$this->error(ERROR_BAD_REQUEST, ERROR_INVALID_GRANT);
-
+
if ($stored["expires"] < time())
$this->error(ERROR_BAD_REQUEST, ERROR_EXPIRED_TOKEN);

// store the refresh token locally so we can delete it when a new refresh token is generated
$this->old_refresh_token = $stored["token"];
-
+
break;
case NONE_GRANT_TYPE:
$stored = $this->check_none_access($client[0]);
@@ -562,7 +562,7 @@
$filters = array(
"client_id" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_CLIENT_ID), "flags" => FILTER_REQUIRE_SCALAR),
"response_type" => array("filter" => FILTER_VALIDATE_REGEXP, "options" => array("regexp" => REGEX_AUTH_RESPONSE_TYPE), "flags" => FILTER_REQUIRE_SCALAR),
- "redirect_uri" => array("filter" => FILTER_VALIDATE_URL, "flags" => array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_REQUIRE_SCALAR)),
+ "redirect_uri" => array("filter" => FILTER_SANITIZE_URL),
"state" => array("flags" => FILTER_REQUIRE_SCALAR),
"scope" => array("flags" => FILTER_REQUIRE_SCALAR),
);
@@ -684,7 +684,7 @@
$this->store_refresh_token($token["refresh_token"], $client_id, time() + $this->refresh_token_lifetime, $scope);
// If we've granted a new refresh token, expire the old one
if($this->old_refresh_token)
- $this->expire_refresh_token($this->old_refresh_token);
+ $this->expire_refresh_token($this->old_refresh_token);
}

return $token;
@@ -735,7 +735,7 @@
$this->send_json_headers();
$response = array("error" => $message);
if(ERROR_VERBOSE && $description)
- $response["error_description"] = $description;
+ $response["error_description"] = $description;
echo json_encode($response);
}

@@ -756,4 +756,4 @@

$this->do_redirect_uri_callback($redirect_uri, $result);
}
-}
\ No newline at end of file
+}
diff -r 969fd139d13f server/examples/pdo/lib/pdo_oauth.php
--- a/server/examples/pdo/lib/pdo_oauth.php Sat Sep 04 11:43:41 2010 -0700
+++ b/server/examples/pdo/lib/pdo_oauth.php Sun Oct 31 00:45:12 2010 +0800
@@ -37,12 +37,12 @@

// Little helper function to add a new client to the database
// Do NOT use this in production! This sample code stores the secret in plaintext!
- public function add_client($client_id, $pw, $redirect_uri) {
+ public function add_client($client_id, $client_secret, $redirect_uri) {
try {
- $sql = "insert into clients (client_id, pw, redirect_uri) values (:client_id, :pw, :redirect_uri)";
+ $sql = "insert into clients (client_id, client_secret, redirect_uri) values (:client_id, :client_secret, :redirect_uri)";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(":client_id", $client_id, PDO::PARAM_STR);
- $stmt->bindParam(":pw", $pw, PDO::PARAM_STR);
+ $stmt->bindParam(":client_secret", $client_secret, PDO::PARAM_STR);
$stmt->bindParam(":redirect_uri", $redirect_uri, PDO::PARAM_STR);
$stmt->execute();
} catch (PDOException $e) {
@@ -61,7 +61,7 @@
// Do NOT use this in production! This sample code stores the secret in plaintext!
protected function auth_client_credentials($client_id, $client_secret = null) {
try {
- $sql = "select pw from clients where client_id = :client_id";
+ $sql = "select client_secret from clients where client_id = :client_id";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(":client_id", $client_id, PDO::PARAM_STR);
$stmt->execute();
@@ -71,7 +71,7 @@
if ($client_secret === null)
return $result !== false;

- return $result["pw"] == $client_secret;
+ return $result["client_secret"] == $client_secret;
} catch (PDOException $e) {
$this->handle_exception($e);
}
@@ -95,11 +95,11 @@
}
}

- protected function get_access_token($token_id) {
+ protected function get_access_token($oauth_token) {
try {
- $sql = "select client_id, expires, scope from tokens where id = :token_id";
+ $sql = "select client_id, expires, scope from tokens where oauth_token = :oauth_token";
$stmt = $this->db->prepare($sql);
- $stmt->bindParam(":token_id", $token_id, PDO::PARAM_STR);
+ $stmt->bindParam(":oauth_token", $oauth_token, PDO::PARAM_STR);
$stmt->execute();

$result = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -110,11 +110,11 @@
}
}

- protected function store_access_token($token_id, $client_id, $expires, $scope = null) {
+ protected function store_access_token($oauth_token, $client_id, $expires, $scope = null) {
try {
- $sql = "insert into tokens (id, client_id, expires, scope) values (:id, :client_id, :expires, :scope)";
+ $sql = "insert into tokens (oauth_token, client_id, expires, scope) values (:oauth_token, :client_id, :expires, :scope)";
$stmt = $this->db->prepare($sql);
- $stmt->bindParam(":id", $token_id, PDO::PARAM_STR);
+ $stmt->bindParam(":oauth_token", $oauth_token, PDO::PARAM_STR);
$stmt->bindParam(":client_id", $client_id, PDO::PARAM_STR);
$stmt->bindParam(":expires", $expires, PDO::PARAM_INT);
$stmt->bindParam(":scope", $scope, PDO::PARAM_STR);
@@ -131,9 +131,9 @@

protected function get_stored_auth_code($code) {
try {
- $sql = "select id, client_id, redirect_uri, expires, scope from auth_codes where id = :id";
+ $sql = "select code, client_id, redirect_uri, expires, scope from auth_codes where code = :code";
$stmt = $this->db->prepare($sql);
- $stmt->bindParam(":id", $code, PDO::PARAM_STR);
+ $stmt->bindParam(":code", $code, PDO::PARAM_STR);
$stmt->execute();

$result = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -148,9 +148,9 @@
// Required for AUTH_CODE_GRANT_TYPE
protected function store_auth_code($code, $client_id, $redirect_uri, $expires, $scope) {
try {
- $sql = "insert into auth_codes (id, client_id, redirect_uri, expires, scope) values (:id, :client_id, :redirect_uri, :expires, :scope)";
+ $sql = "insert into auth_codes (code, client_id, redirect_uri, expires, scope) values (:code, :client_id, :redirect_uri, :expires, :scope)";
$stmt = $this->db->prepare($sql);
- $stmt->bindParam(":id", $code, PDO::PARAM_STR);
+ $stmt->bindParam(":code", $code, PDO::PARAM_STR);
$stmt->bindParam(":client_id", $client_id, PDO::PARAM_STR);
$stmt->bindParam(":redirect_uri", $redirect_uri, PDO::PARAM_STR);
$stmt->bindParam(":expires", $expires, PDO::PARAM_INT);
diff -r 969fd139d13f server/examples/pdo/mysql_create_tables.sql
--- a/server/examples/pdo/mysql_create_tables.sql Sat Sep 04 11:43:41 2010 -0700
+++ b/server/examples/pdo/mysql_create_tables.sql Sun Oct 31 00:45:12 2010 +0800
@@ -1,23 +1,25 @@
-CREATE TABLE `clients` (
-`client_id` VARCHAR( 20 ) NOT NULL ,
-`pw` VARCHAR( 20 ) NOT NULL ,
-`redirect_uri` VARCHAR( 200 ) NOT NULL ,
-PRIMARY KEY ( `client_id` )
-)
-
-CREATE TABLE `tokens` (
-`id` VARCHAR( 40 ) NOT NULL ,
-`client_id` VARCHAR( 20 ) NOT NULL ,
-`expires` INT NOT NULL ,
-`scope` VARCHAR( 200 ) NOT NULL ,
-PRIMARY KEY ( `id` )
-)
-
-CREATE TABLE `auth_codes` (
-`id` VARCHAR( 40 ) NOT NULL ,
-`client_id` VARCHAR( 20 ) NOT NULL ,
-`redirect_uri` VARCHAR( 200 ) NOT NULL ,
-`expires` INT NOT NULL ,
-`scope` VARCHAR( 250 ) NOT NULL ,
-PRIMARY KEY ( `id` )
-)
\ No newline at end of file
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+CREATE TABLE `auth_codes` (
+ `code` varchar(40) NOT NULL,
+ `client_id` varchar(20) NOT NULL,
+ `redirect_uri` varchar(200) NOT NULL,
+ `expires` int(11) NOT NULL,
+ `scope` varchar(250) NOT NULL,
+ PRIMARY KEY (`code`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+CREATE TABLE `clients` (
+ `client_id` varchar(20) NOT NULL,
+ `client_secret` varchar(20) NOT NULL,
+ `redirect_uri` varchar(200) NOT NULL,
+ PRIMARY KEY (`client_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+CREATE TABLE `tokens` (
+ `oauth_token` varchar(40) NOT NULL,
+ `client_id` varchar(20) NOT NULL,
+ `expires` int(11) NOT NULL,
+ `scope` varchar(200) NOT NULL,
+ PRIMARY KEY (`oauth_token`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Powered by Google Project Hosting