Initial commit

master
Lars Vierbergen 7 years ago
commit bfb05b2406
  1. 28
      AuthserverExternalAccountBundle.php
  2. 45
      DependencyInjection/AuthserverExternalAccountExtension.php
  3. 127
      Entity/ExternalUser.php
  4. 44
      Event/LoginButtonEvent.php
  5. 69
      EventListener/LoginTemplateEventListener.php
  6. 31
      ExternalAccountEvents.php
  7. 31
      Resources/config/services.xml
  8. 46
      Resources/migrations/VersionAuthserverExternalAccount20170824135051.php
  9. 10
      Resources/views/Login/buttons.html.twig
  10. 26
      autoload.php

@ -0,0 +1,28 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use vierbergenlars\AuthserverExternalAccountBundle\DependencyInjection\AuthserverExternalAccountExtension;
class AuthserverExternalAccountBundle extends Bundle
{
}

@ -0,0 +1,45 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AuthserverExternalAccountExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$servicesDirectory = __DIR__.'/../Resources/config';
$fileLocator = new FileLocator($servicesDirectory);
$loader = new Loader\XmlFileLoader($container, $fileLocator);
$loader->load('services.xml');
}
}

@ -0,0 +1,127 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle\Entity;
use App\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vierbergenlars_external_account_external_user")
* @Gedmo\Loggable
*/
class ExternalUser
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @var integer
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", fetch="EAGER")
* @Gedmo\Versioned
* @var User
*/
private $user;
/**
* @ORM\Column(type="string")
* @Gedmo\Versioned
* @var string
*/
private $provider;
/**
* @ORM\Column(type="string")
* @Gedmo\Versioned
* @var string
*/
private $provider_ref;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User $user
* @return ExternalUser
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* @return string
*/
public function getProvider()
{
return $this->provider;
}
/**
* @param string $provider
* @return ExternalUser
*/
public function setProvider($provider)
{
$this->provider = $provider;
return $this;
}
/**
* @return string
*/
public function getProviderRef()
{
return $this->provider_ref;
}
/**
* @param string $provider_ref
* @return ExternalUser
*/
public function setProviderRef($provider_ref)
{
$this->provider_ref = $provider_ref;
return $this;
}
}

@ -0,0 +1,44 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle\Event;
use Symfony\Component\EventDispatcher\Event;
class LoginButtonEvent extends Event
{
private $buttons = [];
public function addButton($text, $linkTarget, $style = 'default', $icon = null)
{
$this->buttons[] = [
'text' => $text,
'target' => $linkTarget,
'style' => $style,
'icon' => $icon,
];
}
public function getButtons()
{
return $this->buttons;
}
}

@ -0,0 +1,69 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle\EventListener;
use App\AppEvents;
use App\Event\TemplateEvent;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use vierbergenlars\AuthserverExternalAccountBundle\Event\LoginButtonEvent;
use vierbergenlars\AuthserverExternalAccountBundle\ExternalAccountEvents;
class LoginTemplateEventListener implements EventSubscriberInterface
{
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public static function getSubscribedEvents()
{
return [
AppEvents::LOGIN_VIEW_BODY => ['onLoginViewBody', 1],
];
}
public function onLoginViewBody(TemplateEvent $event)
{
$loginButtonEvent = new LoginButtonEvent();
$this->eventDispatcher->dispatch(ExternalAccountEvents::LOGIN_BUTTON, $loginButtonEvent);
$buttons = $loginButtonEvent->getButtons();
if(count($buttons) > 0) {
$event->setArgument('hiddenPasswordLogin', true);
$event->addTemplate(new TemplateReference('AuthserverExternalAccountBundle', 'Login', 'buttons', 'html', 'twig'), [
'buttons' => $buttons,
]);
}
}
}

@ -0,0 +1,31 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace vierbergenlars\AuthserverExternalAccountBundle;
final class ExternalAccountEvents
{
const LOGIN_BUTTON = 'vierbergenlars.authserver_external_account.login_button';
private function __construct()
{
}
}

@ -0,0 +1,31 @@
<?xml version="1.0" ?>
<!--
~ Authserver, an OAuth2-based single-signon authentication provider written in PHP.
~
~ Copyright (C) $today.date Lars Vierbergen
~
~ his program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<container xmlns="http://symfony.com/schema/dic/services"
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 class="vierbergenlars\AuthserverExternalAccountBundle\EventListener\LoginTemplateEventListener">
<argument type="service" id="event_dispatcher" />
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>

@ -0,0 +1,46 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class VersionAuthserverExternalAccount20170824135051 extends AbstractMigration
{
public function up(Schema $schema)
{
$externalUser = $schema->createTable('vierbergenlars_external_account_external_user');
$externalUser->addColumn('id', 'integer')->setAutoincrement(true);
$externalUser->addColumn('user_id', 'integer');
$externalUser->addColumn('provider', 'string');
$externalUser->addColumn('provider_ref', 'string');
$externalUser->setPrimaryKey(['id']);
$externalUser->addForeignKeyConstraint('auth_users', ['user_id'], ['id']);
}
public function down(Schema $schema)
{
$schema->dropTable('vierbergenlars_external_account_external_user');
}
}

@ -0,0 +1,10 @@
<div class="panel-body">
{% for button in buttons %}
<a class="btn btn-{{ button.style }} btn-block" href="{{ url(button.target) }}">
{% if icon %}
{{ icon(icon) }}
{% endif %}
{{ button.text }}
</a>
{% endfor %}
</div>

@ -0,0 +1,26 @@
<?php
/**
* Authserver, an OAuth2-based single-signon authentication provider written in PHP.
*
* Copyright (C) $today.date Lars Vierbergen
*
* his program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$loader = new \Composer\Autoload\ClassLoader;
$loader->addPsr4('vierbergenlars\\AuthserverExternalAccountBundle\\', __DIR__);
$loader->register();