Added Encryption to Caching

- Access Token is encrypted with Secret Key, and stored in file
- Code to auto-update existing cache files to use encrypted token
- Tests fixes accordingly
This commit is contained in:
japatel
2015-01-26 13:38:17 -06:00
parent d84ddf85c9
commit 830cb16f0f
6 changed files with 128 additions and 11 deletions

View File

@@ -49,6 +49,7 @@ abstract class AuthorizationCache
* @param $accessToken
* @param $tokenCreateTime
* @param $tokenExpiresIn
* @throws \Exception
*/
public static function push($config = null, $clientId, $accessToken, $tokenCreateTime, $tokenExpiresIn)
{
@@ -58,7 +59,7 @@ abstract class AuthorizationCache
$cachePath = self::cachePath($config);
if (!is_dir(dirname($cachePath))) {
if (mkdir(dirname($cachePath), 0755, true) == false) {
return;
throw new \Exception("Failed to create directory at $cachePath");
}
}
@@ -68,12 +69,14 @@ abstract class AuthorizationCache
if (is_array($tokens)) {
$tokens[$clientId] = array(
'clientId' => $clientId,
'accessToken' => $accessToken,
'accessTokenEncrypted' => $accessToken,
'tokenCreateTime' => $tokenCreateTime,
'tokenExpiresIn' => $tokenExpiresIn
);
}
file_put_contents($cachePath, json_encode($tokens));
if(!file_put_contents($cachePath, json_encode($tokens))) {
throw new \Exception("Failed to write cache");
};
}
/**