https://github.com/linkorb/flex-auth
FlexAuth: Framework independent library
https://github.com/linkorb/flex-auth
Last synced: about 1 month ago
JSON representation
FlexAuth: Framework independent library
- Host: GitHub
- URL: https://github.com/linkorb/flex-auth
- Owner: linkorb
- Created: 2019-02-27T12:10:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T12:19:00.000Z (over 2 years ago)
- Last Synced: 2024-09-29T09:18:14.290Z (8 months ago)
- Language: PHP
- Size: 36.1 KB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# flexauth
FlexAuth: independent library for symfony securityAllows switching the `UserProvider` at Runtime using environment variables.
Dynamic UserProvider that supports multiple backends based on environment variables.
To override which should provider configuration as array for runtime
```FlexAuth\FlexAuthTypeProviderInterface```Using ```FlexAuth\FlexAuthTypeProviderFactory::fromEnv('FLEX_AUTH'')``` and define env variables in format
`type?param1=value1¶m2=value2¶m3=value3`Example define environment variable
```
## Use memory provider
FLEX_AUTH=memory?users=alice:4l1c3:ROLE_ADMIN;ROLE_EXAMPLE,bob:b0b:ROLE_EXAMPLE)
## Or use userbase provider
FLEX_AUTH=userbase?dsn=https://username:[email protected]
## Or use the entity provider
FLEX_AUTH=entity?class=\App\Entities\User&property=username
## Or use a JWT provider
FLEX_AUTH=jwt?algo=RS256&publickey=@\cert\public_key.key&private_key=@\cert\privite_key.key&userField=username&groupField=permissions
```A long form format could be supported like this:
```
FLEX_AUTH=entity
FLEX_AUTH_ENTITY_CLASS=\App\Entities\User
FLEX_AUTH_ENTITY_PROPERTY=username
```Dynamically flex type provider example.
```php
class MyFlexAuthTypeProvider implements FlexAuthTypeProviderInterface {
protected $className = \App\Entities\User::class; // can be change in runtime
protected $propery = 'id';
//...
public function provide(): array { // will be call every time
return [
'type' => 'entity',
'class' => $this->className,
'propery' => $this->propery, // dynamic user identificator
];
}
public function switchToEmail() {
$this->propery = 'email';
}
}
```Full working example you can see ```/test/AuthenticationTest::testAuthenticate```
Run tests
```
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
```### Links
[FlexAuthBundle - symfony bundle](https://github.com/linkorb/flex-auth-bundle).
[Demo](https://github.com/linkorb/flex-auth-bundle-demo)[FlexAuthProvider - silex provider](https://github.com/linkorb/flex-auth-provider).
[Demo](https://github.com/linkorb/flex-auth-provider-demo)[The Security Component(Symfony Docs)](https://symfony.com/doc/current/components/security.html)