connectholland / user-bundle
User bundle for Symfony 4 projects
Installs: 4 189
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 15
Forks: 8
Open Issues: 3
Type:symfony-bundle
Requires
- php: ^7.3
- ext-json: *
- doctrine/collections: ^1.6
- doctrine/doctrine-bundle: ^1.11 || ^2.0
- doctrine/orm: ^2.6
- doctrine/persistence: ^1.1 || ^2.0
- gisostallenberg/response-content-negotiation-bundle: ^0.9
- haydenpierce/class-finder: ^0.4.0
- league/html-to-markdown: ^4.8
- php-http/guzzle6-adapter: ^1.0 || ^2.0
- php-http/httplug-bundle: ^1.16
- rollerworks/password-strength-validator: ^1.2
- sensio/framework-extra-bundle: ^5.5
- stof/doctrine-extensions-bundle: ^1.3
- symfony/config: ^4.4 || ^5.0
- symfony/console: ^4.4 || ^5.0
- symfony/css-selector: ^5.2
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/doctrine-bridge: ^4.4 || ^5.0
- symfony/dom-crawler: ^4.4 || ^5.0
- symfony/event-dispatcher: ^4.4 || ^5.0
- symfony/event-dispatcher-contracts: ^1.1 || ^2.0
- symfony/form: ^4.4 || ^5.0
- symfony/framework-bundle: ^4.4 || ^5.0
- symfony/http-foundation: ^4.4 || ^5.0
- symfony/http-kernel: ^4.4 || ^5.0
- symfony/mailer: ^4.4 || ^5.0
- symfony/options-resolver: ^4.4 || ^5.0
- symfony/routing: ^4.4 || ^5.0
- symfony/security-bundle: ^4.4 || ^5.0
- symfony/security-core: ^4.4 || ^5.0
- symfony/security-csrf: ^4.4 || ^5.0
- symfony/security-guard: ^4.4 || ^5.0
- symfony/security-http: ^4.4 || ^5.0
- symfony/templating: ^4.4 || ^5.0
- symfony/translation: ^4.4 || ^5.0
- symfony/twig-bundle: ^4.4 || ^5.0
- symfony/validator: ^4.4 || ^5.0
- twig/twig: ^2.0 || ^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.0.1
- friendsofphp/php-cs-fixer: ^2.15
- hwi/oauth-bundle: ^0.6.3 || ^1.0
- icanhazstring/composer-unused: ^0.7.5
- maglnet/composer-require-checker: ^2.0
- nikic/php-parser: ^4.9
- php-http/guzzle6-adapter: ^1.0 || ^2.0
- php-http/httplug-bundle: ^1.16
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.3
- rector/rector: ^0.8.6
- sensiolabs/security-checker: ^6.0
- symfony/var-dumper: ^4.4 || ^5.0
Suggests
- api-platform/api-pack: Add api-platform/api-pack to add API support to the user bundle, run 'composer req api-pack' to install and follow api platform installation instructions.
- hwi/oauth-bundle: Add hwi/oauth-bundle to be able using OAuth logins, run 'composer require hwi/oauth-bundle' to install.
- lexik/jwt-authentication-bundle: Add lexik/jwt-authentication-bundle to add JWT token support, run 'composer require lexik/jwt-authentication-bundle' to install.
- nelmio/api-doc-bundle: Add nelmio/api-doc-bundle to add comprehensive API documentation, run 'composer require nelmio/api-doc-bundle' to install the Nelmio API Doc bundle and follow the bundle installation and configuration instructions.
README
User bundle for Symfony 4.4 and 5 projects
Functionality
This bundle will be extendible and provide:
- Simple registration form
- Simple login form
- A Command to create users with their roles
- An e-mail message with a secure link to complete account registration
- Recover password functionality
- Ability to 'switch on' OAuth (Google/GitHub/Facebook/etc)
- Being API accessable
- Ability to 'switch on' MFA
Environment
Set the environment variables to be able to send e-mails.
USERBUNDLE_FROM_EMAILADDRESS=example@example.com
Create a user
To create a new user run:
./bin/console connectholland:user:create example@example.com p@$$w0rd --role=ROLE_USER
OAuth
If the app needs OAuth login the HWI OAuth bundle should be required and suitable configuration should be added.
Install the bundle:
composer require hwi/oauth-bundle
Uncomment the oauth include in the routing.
Add environment variables to enable a specific OAuth provider (resource). E.g. for google:
USERBUNDLE_OAUTH_GOOGLE_ID=xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com USERBUNDLE_OAUTH_GOOGLE_SECRET=XXXXXXXXXXX-xx_xx_xxxxx USERBUNDLE_OAUTH_GOOGLE_SCOPE='email profile' # Options specific for the provider can be added in a json encoded string like below. USERBUNDLE_OAUTH_GOOGLE_OPTIONS={"hd": "connectholland.nl"}
Add (automated) routing configuration:
# config/routes/connectholland_user.yaml connectholland_user_oauth: resource: '@ConnecthollandUserBundle/Resources/config/routing_oauth.yaml' prefix: '/'
JTW Token support
If the app needs JTW token support, the Lexik JWT Authentication bundle should be required and suitable configuration should be added.
Intstall the bundle:
composer require lexik/jwt-authentication-bundle
Generate public and secret keys as described in Lexik JWT Authentication bunle documentation.
Set the location of the keys relative to the project root as environment variables JWT_SECRET_KEY
and JWT_PUBLIC_KEY
and set the passphrase used as JWT_PASSPHRASE
API Support
To add API support, install the API Platform and JWT Authentication configure the firewall and add an authentication route.
composer req api-pack jwt-auth
# Example of the security settings for your project. # config/packages/security.yaml firewalls: api_login: pattern: ^/api/users/authenticate stateless: true anonymous: true provider: app_user_provider json_login: check_path: /api/users/authenticate success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure require_previous_session: false api: pattern: ^/api stateless: true anonymous: true provider: app_user_provider json_login: check_path: /api/users/authenticate success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure require_previous_session: false guard: authenticators: - lexik_jwt_authentication.jwt_token_authenticator access_control: - { path: ^/api/authenticate, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/api, roles: ROLE_USER }
# config/routes.yaml api_authenticate: path: /api/users/authenticate
For example:
###> lexik/jwt-authentication-bundle ### JWT_SECRET_KEY=config/jwt/private.pem JWT_PUBLIC_KEY=config/jwt/public.pem JWT_PASSPHRASE=DEVELOPMENT-KSZEW-YHMIE-XWWCL-DBGPQ-MSYCU-RJRWL-UIYBH-TPNXM-GJTVU-BRDQI-XWXHX ###< lexik/jwt-authentication-bundle ###
Security configuration example
security: encoders: Symfony\Component\Security\Core\User\UserInterface: algorithm: auto providers: app_user_provider: entity: class: ConnectHolland\UserBundle\Entity\User property: email firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: anonymous: true guard: authenticators: - ConnectHolland\UserBundle\Security\UserBundleAuthenticator logout: path: connectholland_user_logout oauth: use_forward: false resource_owners: # The resource_owners routing postfixes are a composition of the firewall name and the resource name google: connectholland_user_oauth_check_main_google facebook: connectholland_user_oauth_check_main_facebook linkedin: connectholland_user_oauth_check_main_linkedin # etcetera login_path: connectholland_user_login failure_path: connectholland_user_login oauth_user_provider: service: ConnectHolland\UserBundle\Security\OAuthUserProvider access_control: - { path: ^/(login|inloggen|register|registreren|password-reset|wachtwoord-vergeten), roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: [ROLE_OAUTH, ROLE_ADMIN ] }
Extend User entity
If you want to extend the User entity, you should clone User and add it as entity in your own project.