Browse Source

Authentication is done

dev-master
Simon Vieille 4 years ago
parent
commit
9f21fc2ca0
7 changed files with 246 additions and 10 deletions
  1. +1
    -0
      .gitignore
  2. +17
    -0
      src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php
  3. +181
    -0
      src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php
  4. +34
    -0
      src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php
  5. +9
    -2
      src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php
  6. +3
    -2
      src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml
  7. +1
    -6
      src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml

+ 1
- 0
.gitignore View File

@ -12,3 +12,4 @@
/composer.phar
**/src/**/om/*
**/src/**/map/*
app/propel/

+ 17
- 0
src/Deblan/Bundle/RtmpBundle/AuthProvider/AuthProvider.php View File

@ -0,0 +1,17 @@
<?php
namespace Deblan\Bundle\RtmpBundle\AuthProvider;
/**
* Class AuthProvider
* @author Simon Vieille <simon@deblan.fr>
*/
interface AuthProvider
{
/**
* Returns the authentication validity
*
* @return bool
*/
public function isValid();
}

+ 181
- 0
src/Deblan/Bundle/RtmpBundle/AuthProvider/PropelAuthProvider.php View File

@ -0,0 +1,181 @@
<?php
namespace Deblan\Bundle\RtmpBundle\AuthProvider;
use Symfony\Component\HttpFoundation\Request;
use Deblan\Bundle\RtmpBundle\Model\StreamQuery;
use Deblan\Bundle\RtmpBundle\Model\AccountQuery;
/**
* Class PropelAuthProvider.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class PropelAuthProvider implements AuthProvider
{
/**
* @var string
*/
protected $host;
/**
* @var string
*/
protected $path;
/**
* @var string
*/
protected $key;
/**
* @var string
*/
protected $name;
/**
* @param string $host
*
* @return __CLASS__
*/
public function setHost($host)
{
$this->host = (string) $host;
return $this;
}
/**
* @return string
*/
public function getHost()
{
return $this->host;
}
/**
* @param string $path
*
* @return __CLASS__
*/
public function setPath($path)
{
$this->path = (string) $path;
return $this;
}
/**
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* @param string $name
*
* @return PropelAuthProvider
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $key
*
* @return PropelAuthProvider
*/
public function setKey($key)
{
$this->key = (string) $key;
return $this;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* Handles a request
*
* @param Request $request
*
* @return PropelAuthProvider
*/
public function handleRequest(Request $request)
{
$bag = $request->isMethod('post') ? $request->request : $request->query;
$this->setName($bag->get('name'));
$parse = parse_url($bag->get('swfurl'));
if (!empty($parse['host'])) {
$this->setHost($parse['host']);
}
if (!empty($parse['path'])) {
$this->setPath($parse['path']);
}
if (!empty($parse['query'])) {
$regex = '/key=([^&]+)/';
preg_match($regex, $parse['query'], $match);
if (!empty($match[1])) {
$this->setKey($match[1]);
}
}
}
/**
* {@inheritdoc}
*/
public function isValid()
{
$accounts = AccountQuery::create()
->filterByChannel($this->getName())
->filterByKey($this->getKey())
->find();
if ($accounts->count() === 0) {
return false;
}
$stream = StreamQuery::create()
->filterByHost($this->getHost())
->filterByPath($this->getPath())
->findOne();
if ($stream === null) {
return false;
}
foreach ($accounts as $account) {
if ($account->getStreams()->contains($stream)) {
return true;
}
}
return false;
}
}

+ 34
- 0
src/Deblan/Bundle/RtmpBundle/Command/TestCommand.php View File

@ -0,0 +1,34 @@
<?php
namespace Deblan\Bundle\RtmpBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
* @author Simon Vieille <simon@deblan.fr>
*/
class TestCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('test');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$foo = 'rtmp://local.stream-server/live?key=myPassword';
$parse = parse_url($foo);
var_dump($parse);
}
}

+ 9
- 2
src/Deblan/Bundle/RtmpBundle/Controller/AuthController.php View File

@ -5,6 +5,7 @@ namespace Deblan\Bundle\RtmpBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
/**
* @author Simon Vieille <simon@deblan.fr>
@ -12,12 +13,18 @@ use Symfony\Component\Routing\Annotation\Route;
class AuthController extends Controller
{
/**
* @Route("/auth", name="auth")
* @param Request $request
*
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
* @return Response
*
* @Route("/auth", name="auth")
*/
public function authAction(Request $request)
{
$authProvider = $this->container->get('rtmp.auth.propel_provider');
$authProvider->handleRequest($request);
return new Response(null, $authProvider->isValid() ? 200 : 401);
}
}

+ 3
- 2
src/Deblan/Bundle/RtmpBundle/Resources/config/propel/schema.xml View File

@ -2,7 +2,8 @@
<database defaultIdMethod="native" name="default" namespace="Deblan\Bundle\RtmpBundle\Model">
<table name="stream">
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
<column name="uri" type="VARCHAR" size="255" required="true" />
<column name="host" type="VARCHAR" size="255" required="true" />
<column name="path" type="VARCHAR" size="255" required="true" />
<behavior name="timestampable"/>
</table>
@ -16,7 +17,7 @@
<behavior name="timestampable"/>
</table>
<table name="account_has_stream">
<table name="account_has_stream" isCrossRef="true">
<column name="stream_id" type="integer" required="true" primaryKey="true" />
<column name="account_id" type="integer" required="true" primaryKey="true" />

+ 1
- 6
src/Deblan/Bundle/RtmpBundle/Resources/config/services.xml View File

@ -4,13 +4,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<!--
<services>
<service id="deblan_rtmp.example" class="Deblan\Bundle\RtmpBundle\Example">
<argument type="service" id="service_id" />
<argument>plain_value</argument>
<argument>%parameter_name%</argument>
<service id="rtmp.auth.propel_provider" class="Deblan\Bundle\RtmpBundle\AuthProvider\PropelAuthProvider">
</service>
</services>
-->
</container>

Loading…
Cancel
Save