Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9bd0a0f

Browse files
committed
Refactor private methods to protected.
This is driven by my belief a library must allow for consumers to be open to extending the methods to suit their own needs. In the case of authentication there are an endless list of potential scenarios where users may need to handle scopes differently then the root class defines. This is only one example. Cleaned up namespace statements and use declarations to be PSR1 compatable.
1 parent 78daaf6 commit 9bd0a0f

12 files changed

+73
-56
lines changed

library/OAuth2/Client.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace OAuth2;
3+
24
/**
35
*
46
*
@@ -7,8 +9,8 @@
79
* @package OAuth2
810
*
911
*/
10-
namespace OAuth2;
1112
use OAuth2\Exception\Exception;
13+
1214
/**
1315
* @category OAuth2
1416
* @package OAuth2
@@ -353,7 +355,7 @@ public function getAccessToken() {
353355
* A valid OAuth2.0 JSON decoded access token in associative array, and
354356
* NULL if not enough parameters or JSON decode failed.
355357
*/
356-
private function getAccessTokenFromAuthorizationCode($code) {
358+
protected function getAccessTokenFromAuthorizationCode($code) {
357359
if ($this->getVariable('access_token_uri') && $this->getVariable('client_id') && $this->getVariable('client_secret')) {
358360
return json_decode($this->makeRequest(
359361
$this->getVariable('access_token_uri'),
@@ -386,7 +388,7 @@ private function getAccessTokenFromAuthorizationCode($code) {
386388
* A valid OAuth2.0 JSON decoded access token in associative array, and
387389
* NULL if not enough parameters or JSON decode failed.
388390
*/
389-
private function getAccessTokenFromPassword($username, $password) {
391+
protected function getAccessTokenFromPassword($username, $password) {
390392
if ($this->getVariable('access_token_uri') && $this->getVariable('client_id') && $this->getVariable('client_secret')) {
391393
return json_decode($this->makeRequest(
392394
$this->getVariable('access_token_uri'),
@@ -527,7 +529,7 @@ protected function makeRequest($path, $method = 'GET', $params = array(), $ch =
527529
* @return
528530
* The cookie name.
529531
*/
530-
private function getSessionCookieName() {
532+
protected function getSessionCookieName() {
531533
return 'oauth2_' . $this->getVariable('client_id');
532534
}
533535

library/OAuth2/Grant/GrantImplicitInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
namespace OAuth2\Grant;
3+
24
/**
35
* @category OAuth2
46
* @package OAuth2
57
*/
6-
namespace OAuth2\Grant;
7-
use OAuth2\Storage\StorageInterface,
8-
OAuth2\Server\Server;
8+
use OAuth2\Storage\StorageInterface;
9+
use OAuth2\Server\Server;
10+
911
/**
1012
* @category OAuth2
1113
* @package OAuth2
@@ -25,4 +27,4 @@ interface GrantImplicitInterface extends StorageInterface {
2527
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.2
2628
*/
2729
const RESPONSE_TYPE_TOKEN = Server::RESPONSE_TYPE_ACCESS_TOKEN;
28-
}
30+
}

library/OAuth2/Grant/GrantUserInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
namespace OAuth2\Grant;
3+
24
/**
35
* @category OAuth2
46
* @package OAuth2
57
*/
6-
namespace OAuth2\Grant;
78
use OAuth2\Storage\StorageInterface;
9+
810
/**
911
* @category OAuth2
1012
* @package OAuth2
@@ -50,4 +52,4 @@ interface GrantUserInterface extends StorageInterface {
5052
* @ingroup oauth2_section_4
5153
*/
5254
public function checkUserCredentials($client_id, $username, $password);
53-
}
55+
}

library/OAuth2/RefreshTokensInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
2+
namespace OAuth2;
3+
24
/**
35
*
46
*
57
*
68
* @category OAuth2
79
* @package OAuth2
810
*/
9-
namespace OAuth2;
1011
use OAuth2\Storage\StorageInterface;
12+
1113
/**
1214
* @category OAuth2
1315
* @package OAuth2
@@ -84,4 +86,4 @@ public function setRefreshToken($refresh_token, $client_id, $user_id, $expires,
8486
* @ingroup oauth2_section_6
8587
*/
8688
public function unsetRefreshToken($refresh_token);
87-
}
89+
}

library/OAuth2/Server/MongoServer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
namespace OAuth2\Server;
3+
24
/**
35
* @category OAuth2
46
* @package OAuth2
57
*/
6-
namespace OAuth2\Server;
7-
use OAuth2\Server\Server,
8-
OAuth2\Storage\StorageMongo;
8+
use OAuth2\Server\Server;
9+
use OAuth2\Storage\StorageMongo;
10+
911
/**
1012
* @category OAuth2
1113
* @package OAuth2

library/OAuth2/Server/PdoServer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
namespace OAuth2\Server;
3+
24
/**
35
* @category OAuth2
46
* @package OAuth2
57
*/
6-
namespace OAuth2\Server;
78
use OAuth2\Server\Server;
9+
810
/**
911
* @category OAuth2
1012
* @package OAuth2

library/OAuth2/Server/Server.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<?php
2+
namespace OAuth2\Server;
3+
24
/**
35
*
46
*
57
*
68
* @category OAuth2
79
* @package OAuth2
810
*/
9-
namespace OAuth2\Server;
10-
use ReflectionClass,
11-
Zend_Uri_Http,
12-
OAuth2\Exception\ServerException,
13-
OAuth2\Exception\AuthenticateException,
14-
OAuth2\Exception\RedirectException,
15-
OAuth2\Grant\GrantCodeInterface,
16-
OAuth2\Grant\GrantUserInterface,
17-
OAuth2\Grant\GrantClientInterface,
18-
OAuth2\Grant\GrantImplicitInterface,
19-
OAuth2\Grant\GrantExtensionInterface,
20-
OAuth2\RefreshTokensInterface,
21-
OAuth2\Storage\StorageInterface;
11+
use ReflectionClass;
12+
use Zend_Uri_Http;
13+
use OAuth2\Exception\ServerException;
14+
use OAuth2\Exception\AuthenticateException;
15+
use OAuth2\Exception\RedirectException;
16+
use OAuth2\Grant\GrantCodeInterface;
17+
use OAuth2\Grant\GrantUserInterface;
18+
use OAuth2\Grant\GrantClientInterface;
19+
use OAuth2\Grant\GrantImplicitInterface;
20+
use OAuth2\Grant\GrantExtensionInterface;
21+
use OAuth2\RefreshTokensInterface;
22+
use OAuth2\Storage\StorageInterface;
23+
2224
/**
2325
* @category OAuth2
2426
* @package OAuth2
@@ -47,9 +49,7 @@
4749
*
4850
* @see http://code.google.com/p/oauth2-php/
4951
* @see https://github.com/quizlet/oauth2-php
50-
*/
51-
52-
/**
52+
*
5353
* Server.0 draft v20 server-side implementation.
5454
*
5555
* @todo Add support for Message Authentication Code (MAC) token type.
@@ -627,7 +627,7 @@ public function getBearerToken() {
627627
*
628628
* @ingroup oauth2_section_7
629629
*/
630-
private function checkScope($required_scope, $available_scope) {
630+
protected function checkScope($required_scope, $available_scope) {
631631
// The required scope should match or be a subset of the available scope
632632
if (!is_array($required_scope)) {
633633
$required_scope = explode(' ', trim($required_scope));
@@ -1091,7 +1091,7 @@ public function finishClientAuthorization($is_authorized, $user_id = null, $para
10911091
*
10921092
* @ingroup oauth2_section_4
10931093
*/
1094-
private function doRedirectUriCallback($redirect_uri, $params) {
1094+
protected function doRedirectUriCallback($redirect_uri, $params) {
10951095
header("HTTP/1.1 " . self::HTTP_FOUND);
10961096
header("Location: " . $this->buildUri($redirect_uri, $params));
10971097
exit();
@@ -1110,7 +1110,7 @@ private function doRedirectUriCallback($redirect_uri, $params) {
11101110
*
11111111
* @ingroup oauth2_section_4
11121112
*/
1113-
private function buildUri($uri, $params) {
1113+
protected function buildUri($uri, $params) {
11141114
$uri = Zend_Uri_Http::fromString($uri);
11151115
$uri->setQuery($params['fragment']);
11161116
foreach ( $params as $k => $v ) {
@@ -1175,7 +1175,7 @@ protected function createAccessToken($client_id, $user_id, $scope = null) {
11751175
*
11761176
* @ingroup oauth2_section_4
11771177
*/
1178-
private function createAuthCode($client_id, $user_id, $redirect_uri, $scope = null) {
1178+
protected function createAuthCode($client_id, $user_id, $redirect_uri, $scope = null) {
11791179
$code = $this->genAuthCode();
11801180
$this->storage->setAuthCode($code, $client_id, $user_id, $redirect_uri, time() + $this->getVariable(self::CONFIG_AUTH_LIFETIME), $scope);
11811181
return $code;
@@ -1249,7 +1249,7 @@ protected function getAuthorizationHeader() {
12491249
*
12501250
* @ingroup oauth2_section_5
12511251
*/
1252-
private function sendJsonHeaders() {
1252+
protected function sendJsonHeaders() {
12531253
if (php_sapi_name() === 'cli' || headers_sent()) {
12541254
return;
12551255
}

library/OAuth2/Storage/StorageInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
namespace OAuth2\Storage;
3+
24
/**
35
*
46
*
57
*
68
* @category OAuth2
79
* @package OAuth2
810
*/
9-
namespace OAuth2\Storage;
1011
/**
1112
* @category OAuth2
1213
* @package OAuth2
@@ -109,4 +110,4 @@ public function setAccessToken($oauth_token, $client_id, $user_id, $expires, $sc
109110
* @ingroup oauth2_section_4
110111
*/
111112
public function checkRestrictedGrantType($client_id, $grant_type);
112-
}
113+
}

library/OAuth2/Storage/StorageMongo.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?php
2+
namespace OAuth2\Storage;
3+
24
/**
35
*
46
*
57
*
68
* @category OAuth2
79
* @package OAuth2
810
*/
9-
namespace OAuth2\Storage;
10-
use OAuth2\Grant\GrantCodeInterface,
11-
OAuth2\RefreshTokensInterface,
12-
MongoException,
13-
MongoDB;
11+
use OAuth2\Grant\GrantCodeInterface;
12+
use OAuth2\RefreshTokensInterface;
13+
use MongoException;
14+
use MongoDB;
15+
1416
/**
1517
* @category OAuth2
1618
* @package OAuth2
@@ -35,7 +37,7 @@ class StorageMongo implements GrantCodeInterface, RefreshTokensInterface
3537
/**
3638
* @var MongoDB
3739
*/
38-
private $db;
40+
protected $db;
3941

4042
/**
4143
* Implements Server::__construct().
@@ -78,7 +80,7 @@ protected function _isValid($client_secret, $pw)
7880
/**
7981
* Handle MongoException cases.
8082
*/
81-
private function handleException($e) {
83+
protected function handleException($e) {
8284
echo 'Database error: ' . $e->getMessage();
8385
exit;
8486
}

library/OAuth2/Storage/StoragePdo.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace OAuth2\Storage;
3+
24
/**
35
* @category OAuth2
46
* @package OAuth2
@@ -8,11 +10,10 @@
810
* Simply pass in a configured PDO class, eg:
911
* new OAuth2StoragePDO( new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass') );
1012
*/
11-
namespace OAuth2\Storage;
12-
use OAuth2\Grant\GrantCodeInterface,
13-
OAuth2\RefreshTokensInterface,
14-
PDOException,
15-
PDO;
13+
use OAuth2\Grant\GrantCodeInterface;
14+
use OAuth2\RefreshTokensInterface;
15+
use PDOException;
16+
use PDO;
1617

1718
/**
1819
* PDO storage engine for the OAuth2 Library.
@@ -44,7 +45,7 @@ class StoragePdo implements GrantCodeInterface, RefreshTokensInterface {
4445
/**
4546
* @var PDO
4647
*/
47-
private $db;
48+
protected $db;
4849

4950
/**
5051
* Implements OAuth2::__construct().
@@ -68,7 +69,7 @@ function __destruct() {
6869
/**
6970
* Handle PDO exceptional cases.
7071
*/
71-
private function handleException($e) {
72+
protected function handleException($e) {
7273
echo 'Database error: ' . $e->getMessage();
7374
exit();
7475
}

0 commit comments

Comments
 (0)