Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Jul 8, 2014
1 parent 35b6506 commit 3c759da
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/OAuth2/ClientAssertionType/HttpBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function getClientCredentials(RequestInterface $request, ResponseInterfac
* client_secret can be null if the client's password is an empty string
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
*/

return array('client_id' => $request->request('client_id'), 'client_secret' => $request->request('client_secret'));
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/OAuth2/OpenID/Controller/AuthorizeControllerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace OAuth2\OpenID\Controller;

use OAuth2\RequestInterface;
use OAuth2\ResponseInterface;

interface AuthorizeControllerInterface
{
const RESPONSE_TYPE_ID_TOKEN = 'id_token';
Expand Down
3 changes: 0 additions & 3 deletions src/OAuth2/OpenID/GrantType/AuthorizationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace OAuth2\OpenID\GrantType;

use OAuth2\GrantType\AuthorizationCode as BaseAuthorizationCode;
use OAuth2\Storage\AuthorizationCodeInterface;
use OAuth2\ResponseType\AccessTokenInterface;
use OAuth2\RequestInterface;
use OAuth2\ResponseInterface;

/**
*
Expand Down
1 change: 0 additions & 1 deletion src/OAuth2/OpenID/ResponseType/IdToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OAuth2\Encryption\EncryptionInterface;
use OAuth2\Encryption\Jwt;
use OAuth2\Storage\RefreshTokenInterface;
use OAuth2\Storage\PublicKeyInterface;
use OAuth2\OpenID\Storage\UserClaimsInterface;

Expand Down
1 change: 0 additions & 1 deletion src/OAuth2/OpenID/ResponseType/TokenIdToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OAuth2\OpenID\ResponseType;

use OAuth2\ResponseType\AccessTokenInterface;
use OAuth2\ResponseType\ResponseTypeInterface;

class TokenIdToken implements TokenIdTokenInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/OAuth2/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function headers($name, $default = null)
{
$headers = array_change_key_case($this->headers);
$name = strtolower($name);

return isset($headers[$name]) ? $headers[$name] : $default;
}

Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/ResponseType/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ protected function generateAccessToken()
$tokenLen = 40;
if (function_exists('mcrypt_create_iv')) {
$randomData = mcrypt_create_iv(100, MCRYPT_DEV_URANDOM);
} else if (function_exists('openssl_random_pseudo_bytes')) {
} elseif (function_exists('openssl_random_pseudo_bytes')) {
$randomData = openssl_random_pseudo_bytes(100);
} else if (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
} elseif (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
$randomData = file_get_contents('/dev/urandom', false, null, 0, 100) . uniqid(mt_rand(), true);
} else {
$randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/ResponseType/AuthorizationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ protected function generateAuthorizationCode()
$tokenLen = 40;
if (function_exists('mcrypt_create_iv')) {
$randomData = mcrypt_create_iv(100, MCRYPT_DEV_URANDOM);
} else if (function_exists('openssl_random_pseudo_bytes')) {
} elseif (function_exists('openssl_random_pseudo_bytes')) {
$randomData = openssl_random_pseudo_bytes(100);
} else if (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
} elseif (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
$randomData = file_get_contents('/dev/urandom', false, null, 0, 100) . uniqid(mt_rand(), true);
} else {
$randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public function scopeExists($scope)
$nonReservedScopes = array_diff($scope, $reservedScope);
if (count($nonReservedScopes) == 0) {
return true;
}
else {
} else {
// Check the storage for non-reserved scopes.
$nonReservedScopes = implode(' ', $nonReservedScopes);

return $this->storage->scopeExists($nonReservedScopes);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/OAuth2/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ protected function createDefaultIdTokenResponseType()
}

$config = array_intersect_key($this->config, array_flip(explode(' ', 'issuer id_lifetime')));

return new IdToken($this->storages['user_claims'], $this->storages['public_key'], $config);
}

Expand Down
7 changes: 3 additions & 4 deletions src/OAuth2/Storage/Cassandra.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ protected function setValue($key, $value, $expire = 0)
$seconds = $expire - time();
// __data key set as C* requires a field, note: max TTL can only be 630720000 seconds
$cf->insert($key, array('__data' => $str), null, $seconds);
} catch(\Exception $e) {
} catch (\Exception $e) {
return false;
}
} else {
try {
// __data key set as C* requires a field
$cf->insert($key, array('__data' => $str));
} catch(\Exception $e) {
} catch (\Exception $e) {
return false;
}
}
Expand All @@ -135,7 +135,7 @@ protected function expireValue($key)
try {
// __data key set as C* requires a field
$cf->remove($key, array('__data'));
} catch(\Exception $e) {
} catch (\Exception $e) {
return false;
}

Expand Down Expand Up @@ -364,4 +364,3 @@ public function setJti($client_id, $subject, $audience, $expiration, $jti)
throw new \Exception('setJti() for the Cassandra driver is currently unimplemented.');
}
}

39 changes: 19 additions & 20 deletions src/OAuth2/Storage/DynamoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
*
* @author Frederic AUGUSTE <frederic.auguste at gmail dot com>
*/
class DynamoDB implements AuthorizationCodeInterface,
AccessTokenInterface,
ClientCredentialsInterface,
UserCredentialsInterface,
RefreshTokenInterface,
JwtBearerInterface,
ScopeInterface,
PublicKeyInterface,
UserClaimsInterface,
OpenIDAuthorizationCodeInterface
class DynamoDB implements
AuthorizationCodeInterface,
AccessTokenInterface,
ClientCredentialsInterface,
UserCredentialsInterface,
RefreshTokenInterface,
JwtBearerInterface,
ScopeInterface,
PublicKeyInterface,
UserClaimsInterface,
OpenIDAuthorizationCodeInterface
{
protected $client;
protected $config;
Expand All @@ -59,11 +60,10 @@ public function __construct($connection, $config = array())
'secret' => $connection["secret"],
'region' =>$connection["region"]
));
}
else {
} else {
$this->client = $connection;
}

$this->config = array_merge(array(
'client_table' => 'oauth_clients',
'access_token_table' => 'oauth_access_tokens',
Expand Down Expand Up @@ -129,7 +129,7 @@ public function getClientDetails($client_id)
}
$result = $this->dynamo2array($result);
foreach (array('client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'user_id') as $key => $val) {
if(!array_key_exists ($val, $result)) {
if (!array_key_exists ($val, $result)) {
$result[$val] = null;
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public function getAccessToken($access_token)
return false ;
}
$token = $this->dynamo2array($result);
if(array_key_exists ('expires', $token)) {
if (array_key_exists ('expires', $token)) {
$token['expires'] = strtotime($token['expires']);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ public function getAuthorizationCode($code)
return false ;
}
$token = $this->dynamo2array($result);
if(!array_key_exists("id_token", $token )) {
if (!array_key_exists("id_token", $token )) {
$token['id_token'] = null;
}
$token['expires'] = strtotime($token['expires']);
Expand Down Expand Up @@ -266,7 +266,7 @@ public function getUserClaims($user_id, $claims)
if (!$userDetails = $this->getUserDetails($user_id)) {
return false;
}

$claims = explode(' ', trim($claims));
$userClaims = array();

Expand All @@ -293,10 +293,9 @@ protected function getUserClaim($claim, $userDetails)
$claimValues = explode(' ', $claimValuesString);

foreach ($claimValues as $value) {
if($value == 'email_verified') {
if ($value == 'email_verified') {
$userClaims[$value] = $userDetails[$value]=='true' ? true : false;
}
else {
} else {
$userClaims[$value] = isset($userDetails[$value]) ? $userDetails[$value] : null;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/OAuth2/Storage/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*
* @author Brent Shaffer <bshafs at gmail dot com>
*/
class Pdo implements AuthorizationCodeInterface,
class Pdo implements
AuthorizationCodeInterface,
AccessTokenInterface,
ClientCredentialsInterface,
UserCredentialsInterface,
Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2/Storage/ScopeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function scopeExists($scope);
* request_error is returned by the server to force a
* scope request by the client. By returning "null",
* opt out of requiring scopes
*
*
* @param $client_id
* An optional client id that can be used to return customized default scopes.
*
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/TokenType/Bearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function requestHasToken(RequestInterface $request)
$headers = $request->headers('AUTHORIZATION');

// check the header, then the querystring, then the request body
return !empty($headers) || (bool)($request->request($this->config['token_param_name'])) || (bool)($request->query($this->config['token_param_name']));
return !empty($headers) || (bool) ($request->request($this->config['token_param_name'])) || (bool) ($request->query($this->config['token_param_name']));
}

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ public function getAccessTokenParameter(RequestInterface $request, ResponseInter
*
* @see http://tools.ietf.org/html/rfc6750#section-3.1
*/
$methodsUsed = !empty($headers) + (bool)($request->query($this->config['token_param_name'])) + (bool)($request->request($this->config['token_param_name']));
$methodsUsed = !empty($headers) + (bool) ($request->query($this->config['token_param_name'])) + (bool) ($request->request($this->config['token_param_name']));
if ($methodsUsed > 1) {
$response->setError(400, 'invalid_request', 'Only one method may be used to authenticate at a time (Auth header, GET or POST)');

Expand Down
2 changes: 1 addition & 1 deletion test/OAuth2/Controller/TokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OAuth2\Request\TestRequest;
use OAuth2\Response;

class Controller_TokenControllerTest extends \PHPUnit_Framework_TestCase
class TokenControllerTest extends \PHPUnit_Framework_TestCase
{
public function testNoGrantType()
{
Expand Down
1 change: 0 additions & 1 deletion test/OAuth2/GrantType/UserCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function testNoSecretWithPublicClient()
'password' => 'testpass', // valid password
));


$token = $server->grantAccessToken($request, $response = new Response());

$this->assertNotNull($token);
Expand Down
2 changes: 1 addition & 1 deletion test/OAuth2/OpenID/Controller/UserInfoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OAuth2\Storage\Bootstrap;
use OAuth2\Server;
use OAuth2\GrantType\AuthorizationCode;
use OAuth2\Request;
use OAuth2\Response;

Expand All @@ -28,6 +27,7 @@ private function getTestServer($config = array())
{
$storage = Bootstrap::getInstance()->getMemoryStorage();
$server = new Server($storage, $config);

return $server;
}
}
2 changes: 1 addition & 1 deletion test/OAuth2/OpenID/ResponseType/TokenIdTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function validateIdToken($id_token)
// Each part is a base64url encoded json string.
$part = str_replace(array('-', '_'), array('+', '/'), $part);
$part = base64_decode($part);
$part = json_decode($part, TRUE);
$part = json_decode($part, true);
}
list($header, $claims, $signature) = $parts;

Expand Down
1 change: 0 additions & 1 deletion test/OAuth2/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OAuth2;

use OAuth2\Storage\Memory;
use OAuth2\Storage\Bootstrap;

class ScopeTest extends \PHPUnit_Framework_TestCase
{
Expand Down
2 changes: 0 additions & 2 deletions test/OAuth2/Storage/PdoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace OAuth2\Storage;

use OAuth2\Encryption\Jwt;

class PdoTest extends BaseTest
{
public function testCreatePdoStorageUsingPdoClass()
Expand Down
1 change: 1 addition & 0 deletions test/lib/OAuth2/Storage/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function provideStorage()

/* hack until we can fix "default_scope" dependencies in other tests */
$memory->defaultScope = 'defaultscope1 defaultscope2';

return array(
array($memory),
array($sqlite),
Expand Down
2 changes: 1 addition & 1 deletion test/lib/OAuth2/Storage/NullStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public function getMessage()

return $this->name;
}
}
}

0 comments on commit 3c759da

Please sign in to comment.