Created
January 22, 2016 20:24
-
-
Save onewheelskyward/45c096b077ad4244716e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file intended as a stop-gap to decrypt access tokens mid-migrations. | |
* After this is ran on live databases, remove this file. | |
*/ | |
require_once 'vendor/autoload.php'; | |
$yaml = new \Symfony\Component\Yaml\Yaml(); | |
$parameters = $yaml->parse(file_get_contents(__DIR__ . '/app/config/parameters.yml'))['parameters']; | |
$cypher = new \Igniter\Security\Encryption\Cipher($parameters['secret']); | |
// create db conn | |
$pdo = new PDO( | |
"mysql:host={$parameters['pages.database_host']};dbname={$parameters['pages.database_name']}", | |
$parameters['pages.database_user'], $parameters['pages.database_password'], | |
$parameters['pages.database_options'] ? [PDO::MYSQL_ATTR_SSL_CA => __DIR__ . '/app/config/keys/rds-combined-ca-bundle.pem'] : null | |
); | |
// get all the encrypted access tokens | |
$encrypteds = $pdo->prepare('SELECT id, persistent_access_token FROM facebook_session'); | |
if ($encrypteds->execute()) { | |
while ($encrypted = $encrypteds->fetch(PDO::FETCH_ASSOC)) { | |
// insert decrypted token into new column | |
$decrypted = $pdo->prepare('UPDATE facebook_session SET persistent_access_token_clear = ? WHERE id = ?'); | |
$decrypted->bindValue(1, $cypher->decrypt($encrypted['persistent_access_token'])); | |
$decrypted->bindValue(2, $encrypted['id']); | |
$decrypted->execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment