Skip to content
Open
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
22 changes: 13 additions & 9 deletions src/OAuth2/Storage/DynamoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OAuth2\Storage;

use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Marshaler;

use OAuth2\OpenID\Storage\UserClaimsInterface;
use OAuth2\OpenID\Storage\AuthorizationCodeInterface as OpenIDAuthorizationCodeInterface;
Expand Down Expand Up @@ -45,6 +46,7 @@ class DynamoDB implements
{
protected $client;
protected $config;
protected $marshaler;

public function __construct($connection, $config = array())
{
Expand Down Expand Up @@ -74,6 +76,8 @@ public function __construct($connection, $config = array())
'scope_table' => 'oauth_scopes',
'public_key_table' => 'oauth_public_keys',
), $config);

$this->marshaler = new Marshaler();
}

/* OAuth2\Storage\ClientCredentialsInterface */
Expand All @@ -84,7 +88,7 @@ public function checkClientCredentials($client_id, $client_secret = null)
"Key" => array('client_id' => array('S' => $client_id))
));

return $result->count()==1 && $result["Item"]["client_secret"]["S"] == $client_secret;
return $result->hasKey('Item') && $result["Item"]["client_secret"]["S"] == $client_secret;
}

public function isPublicClient($client_id)
Expand Down Expand Up @@ -128,7 +132,7 @@ public function setClientDetails($client_id, $client_secret = null, $redirect_ur

$result = $this->client->putItem(array(
'TableName' => $this->config['client_table'],
'Item' => $this->client->formatAttributes($clientData)
'Item' => $this->marshaler->marshalItem($clientData)
));

return true;
Expand Down Expand Up @@ -175,7 +179,7 @@ public function setAccessToken($access_token, $client_id, $user_id, $expires, $s

$result = $this->client->putItem(array(
'TableName' => $this->config['access_token_table'],
'Item' => $this->client->formatAttributes($clientData)
'Item' => $this->marshaler->marshalItem($clientData)
));

return true;
Expand All @@ -186,7 +190,7 @@ public function unsetAccessToken($access_token)
{
$result = $this->client->deleteItem(array(
'TableName' => $this->config['access_token_table'],
'Key' => $this->client->formatAttributes(array("access_token" => $access_token)),
'Key' => $this->marshaler->marshalItem(array("access_token" => $access_token)),
'ReturnValues' => 'ALL_OLD',
));

Expand Down Expand Up @@ -223,7 +227,7 @@ public function setAuthorizationCode($authorization_code, $client_id, $user_id,

$result = $this->client->putItem(array(
'TableName' => $this->config['code_table'],
'Item' => $this->client->formatAttributes($clientData)
'Item' => $this->marshaler->marshalItem($clientData)
));

return true;
Expand All @@ -234,7 +238,7 @@ public function expireAuthorizationCode($code)

$result = $this->client->deleteItem(array(
'TableName' => $this->config['code_table'],
'Key' => $this->client->formatAttributes(array("authorization_code" => $code))
'Key' => $this->marshaler->marshalItem(array("authorization_code" => $code))
));

return true;
Expand Down Expand Up @@ -324,7 +328,7 @@ public function setRefreshToken($refresh_token, $client_id, $user_id, $expires,

$result = $this->client->putItem(array(
'TableName' => $this->config['refresh_token_table'],
'Item' => $this->client->formatAttributes($clientData)
'Item' => $this->marshaler->marshalItem($clientData)
));

return true;
Expand All @@ -334,7 +338,7 @@ public function unsetRefreshToken($refresh_token)
{
$result = $this->client->deleteItem(array(
'TableName' => $this->config['refresh_token_table'],
'Key' => $this->client->formatAttributes(array("refresh_token" => $refresh_token))
'Key' => $this->marshaler->marshalItem(array("refresh_token" => $refresh_token))
));

return true;
Expand Down Expand Up @@ -377,7 +381,7 @@ public function setUser($username, $password, $first_name = null, $last_name = n

$result = $this->client->putItem(array(
'TableName' => $this->config['user_table'],
'Item' => $this->client->formatAttributes($clientData)
'Item' => $this->marshaler->marshalItem($clientData)
));

return true;
Expand Down