linkorb / silex-provider-user-basic
Custom Symfony Security User and in-memory User Provider for use in Silex apps.
Installs: 113
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
pkg:composer/linkorb/silex-provider-user-basic
Requires
- silex/silex: ^2.1
- symfony/console: ^3.2
- symfony/security: ^3.2
This package is auto-updated.
Last update: 2025-10-26 16:30:56 UTC
README
Custom Symfony Security User and in-memory User Provider for use in Silex apps.
First, create an array of users:-
// for example, in src/app.php
$users = [
    'jo' => [
        'password' => '$2y$12$G7...',
        'roles' => ['admin'],
        'display_name' => 'Joseph',
        'enabled' => false,
    ],
    'jen' => [
        'password' => '$2y$12$oD...',
        'roles' => ['admin'],
        'display_name' => 'Jenifer',
    ],
];
The password value is the hashed password; these can be generated with the
accomapnying password hashing command:-
$ vendor/bin/hashpasswd -h
Usage:
  hashpasswd [options]
Options:
  -c, --cost=COST       Algorithmic cost of the hash function. [default: 12]
  -h, --help            Display this help message
Help:
  The command interactively asks for the password before printing its hash.
Next, register Silex's core SecurityServiceProvider and provide a firewall paramater:-
$app->register(
    new SecurityServiceProvider,
    [
        'security.firewalls' => [
            'api' => [
                'pattern' => '^/api',
                'http' => true,
                'users' => function () use ($users) {
                    return new \LinkORB\BasicUser\Provider\UserProvider($users);
                },
            ],
        ],
    ]
);