Skip to content

Commit b24f30d

Browse files
authored
Add mongo db (bshaffer#790)
* add mongodb extension for php 7.x to travis * removes mongodb library for php5 from travis * removes HHVM from travis
1 parent d9f2354 commit b24f30d

File tree

6 files changed

+539
-24
lines changed

6 files changed

+539
-24
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ php:
1111
- 5.6
1212
- 7.0
1313
- 7.1
14-
- hhvm
1514
env:
1615
global:
1716
- secure: Bc5ZqvZ1YYpoPZNNuU2eCB8DS6vBYrAdfBtTenBs5NSxzb+Vjven4kWakbzaMvZjb/Ib7Uph7DGuOtJXpmxnvBXPLd707LZ89oFWN/yqQlZKCcm8iErvJCB5XL+/ONHj2iPdR242HJweMcat6bMCwbVWoNDidjtWMH0U2mYFy3M=
@@ -22,10 +21,11 @@ services:
2221
- cassandra
2322
before_install:
2423
- phpenv config-rm xdebug.ini || return 0
24+
- phpenv version-name | grep ^5.[3-6] && composer remove mongodb/mongodb --dev && echo "extension=mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
25+
- phpenv version-name | grep ^7 && echo "extension=mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
2526
install:
26-
- composer install --no-interaction
27+
- composer install
2728
before_script:
2829
- psql -c 'create database oauth2_server_php;' -U postgres
29-
- phpenv version-name | grep ^5.[3-6] && echo "extension=mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
3030
after_script:
3131
- php test/cleanup.php

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
}
1313
],
1414
"homepage": "http://github.com/bshaffer/oauth2-server-php",
15-
"require":{
16-
"php":">=5.3.9"
17-
},
1815
"autoload": {
1916
"psr-0": { "OAuth2": "src/" }
2017
},
21-
"suggest": {
22-
"predis/predis": "Required to use the Redis storage engine",
23-
"thobbs/phpcassa": "Required to use the Cassandra storage engine",
24-
"aws/aws-sdk-php": "~2.8 is required to use the DynamoDB storage engine",
25-
"firebase/php-jwt": "~2.2 is required to use JWT features"
18+
"require":{
19+
"php":">=5.3.9"
2620
},
2721
"require-dev": {
2822
"aws/aws-sdk-php": "~2.8",
2923
"firebase/php-jwt": "~2.2",
3024
"predis/predis": "dev-master",
31-
"thobbs/phpcassa": "dev-master"
25+
"thobbs/phpcassa": "dev-master",
26+
"mongodb/mongodb": "^1.1"
27+
},
28+
"suggest": {
29+
"predis/predis": "Required to use Redis storage",
30+
"thobbs/phpcassa": "Required to use Cassandra storage",
31+
"aws/aws-sdk-php": "~2.8 is required to use DynamoDB storage",
32+
"firebase/php-jwt": "~1.1 is required to use MondoDB storage"
3233
}
3334
}

src/OAuth2/Storage/Mongo.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Mongo implements AuthorizationCodeInterface,
2222
UserCredentialsInterface,
2323
RefreshTokenInterface,
2424
JwtBearerInterface,
25+
PublicKeyInterface,
2526
OpenIDAuthorizationCodeInterface
2627
{
2728
protected $db;
@@ -46,6 +47,7 @@ public function __construct($connection, $config = array())
4647
'refresh_token_table' => 'oauth_refresh_tokens',
4748
'code_table' => 'oauth_authorization_codes',
4849
'user_table' => 'oauth_users',
50+
'key_table' => 'oauth_keys',
4951
'jwt_table' => 'oauth_jwt',
5052
), $config);
5153
}
@@ -336,4 +338,55 @@ public function setJti($client_id, $subject, $audience, $expiration, $jti)
336338
//TODO: Needs mongodb implementation.
337339
throw new \Exception('setJti() for the MongoDB driver is currently unimplemented.');
338340
}
341+
342+
public function getPublicKey($client_id = null)
343+
{
344+
if ($client_id) {
345+
$result = $this->collection('key_table')->findOne(array(
346+
'client_id' => $client_id
347+
));
348+
if ($result) {
349+
return $result['public_key'];
350+
}
351+
}
352+
353+
$result = $this->collection('key_table')->findOne(array(
354+
'client_id' => null
355+
));
356+
return is_null($result) ? false : $result['public_key'];
357+
}
358+
359+
public function getPrivateKey($client_id = null)
360+
{
361+
if ($client_id) {
362+
$result = $this->collection('key_table')->findOne(array(
363+
'client_id' => $client_id
364+
));
365+
if ($result) {
366+
return $result['private_key'];
367+
}
368+
}
369+
370+
$result = $this->collection('key_table')->findOne(array(
371+
'client_id' => null
372+
));
373+
return is_null($result) ? false : $result['private_key'];
374+
}
375+
376+
public function getEncryptionAlgorithm($client_id = null)
377+
{
378+
if ($client_id) {
379+
$result = $this->collection('key_table')->findOne(array(
380+
'client_id' => $client_id
381+
));
382+
if ($result) {
383+
return $result['encryption_algorithm'];
384+
}
385+
}
386+
387+
$result = $this->collection('key_table')->findOne(array(
388+
'client_id' => null
389+
));
390+
return is_null($result) ? 'RS256' : $result['encryption_algorithm'];
391+
}
339392
}

0 commit comments

Comments
 (0)