Skip to content

Commit

Permalink
Used the official Pusher in as a dependency
Browse files Browse the repository at this point in the history
See #9
  • Loading branch information
Pierre-Louis LAUNAY committed Jun 13, 2013
1 parent e659b16 commit 0c15fa2
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 362 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -17,5 +17,6 @@ xcuserdata
.svn
CVS

vendor/*
!vendor/vendors.php
vendor

.composer.lock
16 changes: 8 additions & 8 deletions .travis.yml
@@ -1,15 +1,15 @@
language: php

php:
- 5.3
- 5.4
- 5.3
- 5.4
- 5.5

env:
- SYMFONY_VERSION=v2.0.6
- SYMFONY_VERSION=origin/master
matrix:
allow_failures:
- php: 5.5

before_script: php vendor/vendors.php
before_script: composer install --dev --prefer-source

notifications:
email:
- laupi.frpar@gmail.com
email: laupi.frpar@gmail.com
12 changes: 6 additions & 6 deletions Authenticator/ChannelAuthenticatorInterface.php
@@ -1,19 +1,19 @@
<?php
/*
*
*/

namespace Lopi\Bundle\PusherBundle\Authenticator;

/**
* ChannelAuthenticatorInterface
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
*/
interface ChannelAuthenticatorInterface
{

/**
* @param string $socketId
* @param string $channelName
* @param string $socketId The socket ID
* @param string $channelName The channel name
*
* @return bool
*/
public function authenticate($socketId, $channelName);
Expand Down
14 changes: 8 additions & 6 deletions Authenticator/ChannelAuthenticatorPresenceInterface.php
@@ -1,22 +1,24 @@
<?php
/*
*
*/

namespace Lopi\Bundle\PusherBundle\Authenticator;

/**
* ChannelAuthenticatorPresenceInterface
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
interface ChannelAuthenticatorPresenceInterface
{
/**
* Returns an optional array of user info
*
*
* @return array
*/
public function getUserInfo();

/**
* Return the user id when authenticated, used for presence channels
*
*
* @returns string
*/
public function getUserId();
Expand Down
26 changes: 13 additions & 13 deletions Controller/AuthController.php
@@ -1,7 +1,4 @@
<?php
/*
*
*/

namespace Lopi\Bundle\PusherBundle\Controller;

Expand All @@ -11,6 +8,8 @@
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
* AuthController
*
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class AuthController extends ContainerAware
Expand All @@ -21,6 +20,8 @@ class AuthController extends ContainerAware
* and http://pusher.com/docs/auth_signatures
*
* @param Request $request
*
* @return Response
*/
public function authAction(Request $request)
{
Expand All @@ -36,24 +37,23 @@ public function authAction(Request $request)

if (strpos($channelName, 'presence') === 0) {
$userData = json_encode(array(
'user_id' => $this->container->get('lopi_pusher.authenticator')->getUserId(),
'user_info' => $this->container->get('lopi_pusher.authenticator')->getUserInfo()
'user_id' => $this->container->get('lopi_pusher.authenticator')->getUserId(),
'user_info' => $this->container->get('lopi_pusher.authenticator')->getUserInfo()
));
$code = hash_hmac('sha256', $socketId.':'.$channelName.':'.$userData, $secret);
$auth = $key.':'.$code;
$code = hash_hmac('sha256', $socketId . ':' . $channelName . ':' . $userData, $secret);
$auth = $key . ':' . $code;
$responseData = array(
'auth' => $auth,
'channel_data' => $userData
'auth' => $auth,
'channel_data' => $userData
);
} else {
$code = hash_hmac('sha256', $socketId.':'.$channelName, $secret);
$auth = $key.':'.$code;
$code = hash_hmac('sha256', $socketId . ':' . $channelName, $secret);
$auth = $key . ':' . $code;
$responseData = array(
'auth' => $auth
'auth' => $auth
);
}

return new Response(json_encode($responseData), 200, array('Content-Type' => 'application/json'));
}

}
28 changes: 10 additions & 18 deletions DependencyInjection/Configuration.php
Expand Up @@ -12,7 +12,7 @@
*/
class Configuration implements ConfigurationInterface
{

/**
* Generates the configuration tree builder.
*
Expand All @@ -25,23 +25,15 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('app_id')
->isRequired()
->end()
->scalarNode('key')
->isRequired()
->end()
->scalarNode('secret')
->isRequired()
->end()
->booleanNode('encrypted')
->defaultValue(false)
->end()
->scalarNode('auth_service_id')
->defaultNull()
->end()
->end()
;
->scalarNode('app_id')->isRequired()->end()
->scalarNode('key')->isRequired()->end()
->scalarNode('secret')->isRequired()->end()
->booleanNode('debug')->defaultValue(false)->end()
->scalarNode('host')->defaultValue('http://api.pusherapp.com')->end()
->scalarNode('port')->defaultValue('80')->end()
->scalarNode('timeout')->defaultValue('30')->end()
->scalarNode('auth_service_id')->defaultNull()->end()
->end();

return $treeBuilder;
}
Expand Down
47 changes: 19 additions & 28 deletions DependencyInjection/LopiPusherExtension.php
Expand Up @@ -2,51 +2,42 @@

namespace Lopi\Bundle\PusherBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;

/**
* LopiPusherExtension
*
*/
class LopiPusherExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.xml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

if (!isset($config['app_id']) || $config['app_id'] === null) {
throw new \InvalidArgumentException('Please set the app_id of Pusher');
}


$container->setParameter('lopi_pusher.app.id', $config['app_id']);

if (!isset($config['key']) || $config['key'] === null) {
throw new \InvalidArgumentException('Please set the key of Pusher');
}

$container->setParameter('lopi_pusher.key', $config['key']);

if (!isset($config['secret']) || $config['secret'] === null) {
throw new \InvalidArgumentException('Please set the secret of Pusher');
}

$container->setParameter('lopi_pusher.secret', $config['secret']);

if (isset($config['encrypted'])) {
$container->setParameter('lopi_pusher.encrypted', $config['encrypted']);
}
$container->setParameter('lopi_pusher.debug', $config['debug']);
$container->setParameter('lopi_pusher.host', $config['host']);
$container->setParameter('lopi_pusher.port', $config['port']);
$container->setParameter('lopi_pusher.timeout', $config['timeout']);
$container->setAlias('lopi_pusher.authenticator', $config['auth_service_id']);

if (isset($config['auth_service_id'])) {
$container->setAlias('lopi_pusher.authenticator', $config['auth_service_id']);
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}

/**
* {@inheritdoc}
*/
public function getAlias()
{
return 'lopi_pusher';
Expand Down
78 changes: 0 additions & 78 deletions Pusher/Pusher.php

This file was deleted.

0 comments on commit 0c15fa2

Please sign in to comment.