- Run
composer require kstupak/simple-auth:dev-master
- Make your User implementation extend
SimpleAuth\Model\User
:
<?php
namespace App\Entity;
use App\Model\UserRoles;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use SimpleAuth\Model\User as BaseUser;
class User extends BaseUser
{
/** @var UuidInterface */
private $id;
/** @var array */
private $roles;
public function __construct(
string $name,
string $email,
string $password
){
parent::__construct($name, $email, $password);
$this->roles = [UserRoles::USER];
$this->id = Uuid::uuid4();
}
}
- Create your implementation for
SimpleAuth\UserProvider
:
<?php
namespace App\Service\User;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
final class UserProvider extends \SimpleAuth\UserProvider
{
/** @var EntityRepository */
protected $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(User::class);
}
public function supportsClass($class)
{
return $class = User::class;
}
}
- Add following snippet to
config/packages/doctrine.yaml
:
doctrine:
orm:
mappings:
SimpleAuth\:
is_bundle: false
type: xml
dir: '%kernel.project_dir%/vendor/kstupak/simple-auth/src/Resources/mappings'
prefix: 'SimpleAuth'
alias: SimpleAuth
- Add definition for
uuid_binary
type for doctrine:
# config/packages/ramsey_uuid_doctrine.yaml
doctrine:
dbal:
types:
uuid_binary: 'Ramsey\Uuid\Doctrine\UuidBinaryType'
-
Copy contents of the
vendor/kstupak/simple-auth/src/Resource/security.yaml
toconfig/packages/security.yaml
and replaceproviders.user.id
value with class name of your own user provider implementation -
Register bundle:
<?php
# config/bundles.php
return [
# Here are other bundles
\SimpleAuth\SimpleAuthBundle::class => ['all' => true],
];
- Add routing config to
config/routes.yaml
security:
resource: '../vendor/kstupak/simple-auth/Controller/SecurityController.php'
type: annotation