Installation

1. Require the bundle

composer require derafu/symfony-identity-bundle

If the bundle is consumed as a local path repository during development:

{
  "repositories": [
    { "type": "path", "url": "./packages/DerafuIdentityBundle" }
  ],
  "require": {
    "derafu/symfony-identity-bundle": "*"
  }
}

2. Register the bundle

If Symfony Flex did not register it automatically:

// config/bundles.php
return [
    // ...
    Derafu\IdentityBundle\IdentityBundle::class => ['all' => true],
];

3. Create the concrete entities

The bundle provides abstract Base* classes as MappedSuperclasses. The app must create concrete entities that extend them. Following the Derafu convention, entities are grouped under App\Entity\Auth\:

// src/Entity/Auth/User.php
namespace App\Entity\Auth;

use App\Repository\UserRepository;
use Derafu\IdentityBundle\Entity\BaseUser;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'auth_users')]
class User extends BaseUser {}

Repeat for all entities:

Base class Concrete Table
BaseUser App\Entity\Auth\User auth_users
BaseRole App\Entity\Auth\Role auth_roles
BasePermission App\Entity\Auth\Permission auth_permissions
BaseUserRole App\Entity\Auth\UserRole auth_user_roles
BaseRolePermission App\Entity\Auth\RolePermission auth_role_permissions
BaseOrganization App\Entity\Auth\Organization auth_organizations
BaseOrganizationMembership App\Entity\Auth\OrganizationMembership auth_organization_memberships
BaseOrganizationInvitation App\Entity\Auth\OrganizationInvitation auth_organization_invitations
BaseVerificationToken App\Entity\Auth\VerificationToken auth_verification_tokens
BaseApiKey App\Entity\Auth\ApiKey auth_api_keys
BaseLoginRecord App\Entity\Auth\LoginRecord auth_login_records

4. Create the concrete repositories

For entities that have a base repository:

// src/Repository/UserRepository.php
namespace App\Repository;

use App\Entity\Auth\User;
use Derafu\IdentityBundle\Repository\BaseUserRepository;
use Doctrine\Persistence\ManagerRegistry;

class UserRepository extends BaseUserRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, User::class);
    }
}

Base repositories exist for: User, Organization, VerificationToken, OrganizationMembership, OrganizationInvitation.

5. Configuration (usually not needed)

If you follow the App\Entity\Auth\* convention, zero configuration is required — the defaults match. See configuration for how to override.

6. Run migrations

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

7. Seed initial roles

The bundle does not ship seed data. Create the roles your app needs:

INSERT INTO auth_roles (code, name) VALUES
  ('org.owner', 'Organization Owner'),
  ('org.admin', 'Organization Admin'),
  ('org.member', 'Organization Member');

Or use a Doctrine fixture.

On this page

Last updated on 16/04/2026 by Anonymous