Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mongo db #790

Merged
merged 5 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm
env:
global:
- secure: Bc5ZqvZ1YYpoPZNNuU2eCB8DS6vBYrAdfBtTenBs5NSxzb+Vjven4kWakbzaMvZjb/Ib7Uph7DGuOtJXpmxnvBXPLd707LZ89oFWN/yqQlZKCcm8iErvJCB5XL+/ONHj2iPdR242HJweMcat6bMCwbVWoNDidjtWMH0U2mYFy3M=
Expand All @@ -22,10 +21,11 @@ services:
- cassandra
before_install:
- phpenv config-rm xdebug.ini || return 0
- 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
- phpenv version-name | grep ^7 && echo "extension=mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
install:
- composer install --no-interaction
- composer install
before_script:
- psql -c 'create database oauth2_server_php;' -U postgres
- phpenv version-name | grep ^5.[3-6] && echo "extension=mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
after_script:
- php test/cleanup.php
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
}
],
"homepage": "http://github.com/bshaffer/oauth2-server-php",
"require":{
"php":">=5.3.9"
},
"autoload": {
"psr-0": { "OAuth2": "src/" }
},
"suggest": {
"predis/predis": "Required to use the Redis storage engine",
"thobbs/phpcassa": "Required to use the Cassandra storage engine",
"aws/aws-sdk-php": "~2.8 is required to use the DynamoDB storage engine",
"firebase/php-jwt": "~2.2 is required to use JWT features"
"require":{
"php":">=5.3.9"
},
"require-dev": {
"aws/aws-sdk-php": "~2.8",
"firebase/php-jwt": "~2.2",
"predis/predis": "dev-master",
"thobbs/phpcassa": "dev-master"
"thobbs/phpcassa": "dev-master",
"mongodb/mongodb": "^1.1"
},
"suggest": {
"predis/predis": "Required to use Redis storage",
"thobbs/phpcassa": "Required to use Cassandra storage",
"aws/aws-sdk-php": "~2.8 is required to use DynamoDB storage",
"firebase/php-jwt": "~1.1 is required to use MondoDB storage"
}
}
53 changes: 53 additions & 0 deletions src/OAuth2/Storage/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Mongo implements AuthorizationCodeInterface,
UserCredentialsInterface,
RefreshTokenInterface,
JwtBearerInterface,
PublicKeyInterface,
OpenIDAuthorizationCodeInterface
{
protected $db;
Expand All @@ -46,6 +47,7 @@ public function __construct($connection, $config = array())
'refresh_token_table' => 'oauth_refresh_tokens',
'code_table' => 'oauth_authorization_codes',
'user_table' => 'oauth_users',
'key_table' => 'oauth_keys',
'jwt_table' => 'oauth_jwt',
), $config);
}
Expand Down Expand Up @@ -336,4 +338,55 @@ public function setJti($client_id, $subject, $audience, $expiration, $jti)
//TODO: Needs mongodb implementation.
throw new \Exception('setJti() for the MongoDB driver is currently unimplemented.');
}

public function getPublicKey($client_id = null)
{
if ($client_id) {
$result = $this->collection('key_table')->findOne(array(
'client_id' => $client_id
));
if ($result) {
return $result['public_key'];
}
}

$result = $this->collection('key_table')->findOne(array(
'client_id' => null
));
return is_null($result) ? false : $result['public_key'];
}

public function getPrivateKey($client_id = null)
{
if ($client_id) {
$result = $this->collection('key_table')->findOne(array(
'client_id' => $client_id
));
if ($result) {
return $result['private_key'];
}
}

$result = $this->collection('key_table')->findOne(array(
'client_id' => null
));
return is_null($result) ? false : $result['private_key'];
}

public function getEncryptionAlgorithm($client_id = null)
{
if ($client_id) {
$result = $this->collection('key_table')->findOne(array(
'client_id' => $client_id
));
if ($result) {
return $result['encryption_algorithm'];
}
}

$result = $this->collection('key_table')->findOne(array(
'client_id' => null
));
return is_null($result) ? 'RS256' : $result['encryption_algorithm'];
}
}
Loading