Skip to content

Instantly share code, notes, and snippets.

@onewheelskyward
Created January 22, 2016 20:24
Show Gist options
  • Save onewheelskyward/45c096b077ad4244716e to your computer and use it in GitHub Desktop.
Save onewheelskyward/45c096b077ad4244716e to your computer and use it in GitHub Desktop.
<?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