Skip to content

Commit

Permalink
fixed redirect uri handling when creating oauth user
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Apr 15, 2015
1 parent cbde7a3 commit 1348379
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
$stmt = $conn->prepare('INSERT INTO OAuthClient(random_id, redirect_uris, secret, allowed_grant_types, name, IdPublication, trusted)
VALUES (?, ?, ?, ?, ?, ?, ?)');
$stmt->bindValue(1, Random::generateToken());
$stmt->bindValue(2, serialize(array($alias)));
$stmt->bindValue(2, serialize(array($alias.'/oauth/authentication/result')));
$stmt->bindValue(3, Random::generateToken());
$stmt->bindValue(4, serialize(array('token', 'authorization_code', 'client_credentials', 'password')));
$stmt->bindValue(5, $defaultClientName);
Expand Down
21 changes: 10 additions & 11 deletions newscoop/library/Newscoop/Installer/Services/FinishService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @copyright 2013 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Installer\Services;

use Symfony\Component\Process\PhpExecutableFinder;
Expand All @@ -31,7 +30,7 @@ class FinishService
*/
public function __construct()
{
$this->newscoopDir = __DIR__ . '/../../../..';
$this->newscoopDir = __DIR__.'/../../../..';
$this->filesystem = new Filesystem();
}

Expand Down Expand Up @@ -72,7 +71,7 @@ public function createDefaultOauthClient($alias)

$php = escapeshellarg($phpPath);
$newscoopConsole = escapeshellarg($this->newscoopDir.'/application/console');
$reloadRenditions = new Process("$php $newscoopConsole oauth:create-client newscoop $alias $alias --default", null, null, null, 300);
$reloadRenditions = new Process("$php $newscoopConsole oauth:create-client newscoop $alias --default", null, null, null, 300);
$reloadRenditions->run();
if (!$reloadRenditions->isSuccessful()) {
throw new \RuntimeException('An error occurred when executing the create default oauth client command.');
Expand Down Expand Up @@ -169,7 +168,7 @@ public function saveCronjobs(SchedulerServiceInterface $scheduler)
'command' => $appDirectory.' log:maintenance',
'schedule' => '30 1 * * *',
'enabled' => false,
'detailsUrl' => 'http://sourcefabric.booktype.pro/newscoop-42-for-journalists-and-editors/log-file-maintenance/'
'detailsUrl' => 'http://sourcefabric.booktype.pro/newscoop-42-for-journalists-and-editors/log-file-maintenance/',
));

$crontab = new Crontab();
Expand Down Expand Up @@ -208,7 +207,7 @@ public function saveInstanceConfig($config, $connection)
$password = implode(User::HASH_SEP, array(
User::HASH_ALGO,
$salt,
hash(User::HASH_ALGO, $salt . $config['recheck_user_password']),
hash(User::HASH_ALGO, $salt.$config['recheck_user_password']),
));

$sql = "UPDATE liveuser_users SET Password = ?, EMail = ?, time_updated = NOW(), time_created = NOW(), status = '1', is_admin = '1' WHERE id = 1";
Expand All @@ -219,17 +218,17 @@ public function saveInstanceConfig($config, $connection)

$sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'SiteSecretKey'";
$stmt = $connection->prepare($sql);
$stmt->bindValue(1, sha1($config['site_title'] . mt_rand()));
$stmt->bindValue(1, sha1($config['site_title'].mt_rand()));
$stmt->execute();

$sql = "INSERT INTO SystemPreferences (`varname`, `value`, `last_modified`) VALUES ('installation_id', ?, NOW())";
$stmt = $connection->prepare($sql);
$stmt->bindValue(1, sha1($config['site_title'] . mt_rand()));
$stmt->bindValue(1, sha1($config['site_title'].mt_rand()));
$stmt->execute();

$result = $this->setupHtaccess();
if (!empty($result)) {
throw new IOException(implode(" ", $result) . " Most likely it's caused by wrong permissions.");
throw new IOException(implode(" ", $result)." Most likely it's caused by wrong permissions.");
}
}

Expand All @@ -244,8 +243,8 @@ public function setupHtaccess()
$errors = array();

try {
if ($this->filesystem->exists($this->newscoopDir . $htaccess)) {
$this->filesystem->copy(realpath($this->newscoopDir . $htaccess), realpath($this->newscoopDir) . '/htaccess.bak');
if ($this->filesystem->exists($this->newscoopDir.$htaccess)) {
$this->filesystem->copy(realpath($this->newscoopDir.$htaccess), realpath($this->newscoopDir).'/htaccess.bak');
}
} catch (IOException $e) {
$errors[] = $e->getMessage();
Expand All @@ -254,7 +253,7 @@ public function setupHtaccess()
}

try {
$this->filesystem->copy(realpath($this->newscoopDir . '/htaccess.dist'), realpath($this->newscoopDir) . $htaccess, true);
$this->filesystem->copy(realpath($this->newscoopDir.'/htaccess.dist'), realpath($this->newscoopDir).$htaccess, true);
} catch (IOException $e) {
$errors[] = $e->getMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure()
->setDescription('Create oauth2 client.')
->addArgument('name', InputArgument::REQUIRED, 'Client name')
->addArgument('publication', InputArgument::REQUIRED, 'Publication alias')
->addArgument('redirectUris', InputArgument::REQUIRED, 'Redirect uris')
->addArgument('redirectUris', InputArgument::OPTIONAL, 'Redirect uris')
->addOption('test', null, InputOption::VALUE_NONE, 'If set it will create test client with predefined data (for automatic tests)')
->addOption('default', null, InputOption::VALUE_NONE, 'If set it will create default client with predefined name');
}
Expand All @@ -38,17 +38,23 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getApplication()->getKernel()->getContainer();
$router = $container->get('router');
$em = $container->getService('em');
$clientManager = $container->get('fos_oauth_server.client_manager.default');
$name = $input->getArgument('name');
$publication = $em->getRepository('\Newscoop\Entity\Aliases')
->findOneByName($input->getArgument('publication'))
->getPublication();

$redirectUris = $input->getArgument('redirectUris');
if (is_null($redirectUris)) {
$redirectUris = 'http://'.$input->getArgument('publication');
}

if ($input->getOption('default')) {
$preferencesService = $container->get('preferences');
$defaultClientName = 'newscoop_'.$preferencesService->SiteSecretKey;
$redirectUris = 'http://'.$input->getArgument('publication').$router->generate('oauth_authentication_result');
$client = $em->getRepository('\Newscoop\GimmeBundle\Entity\Client')->findOneByName($defaultClientName);
if ($client) {
return;
Expand Down

0 comments on commit 1348379

Please sign in to comment.