ruwork / manual-auth-bundle
Ruwork Manual Auth Bundle
Installs: 10 597
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- symfony/config: ^3.4 || ^4.0
- symfony/dependency-injection: ^3.4 || ^4.0
- symfony/http-kernel: ^3.4 || ^4.0
- symfony/security-bundle: ^3.4 || ^4.0
This package is auto-updated.
Last update: 2023-06-29 00:56:31 UTC
README
Configuration
# app/config/security.yml security: main: # add manual auth to any firewall manual: ~ anonymous: ~ provider: your_user_provider form_login: # ... logout: # ... remember_me: # configure remember me if you need always_remember_me: true
Authenticating a User in the controller
<?php declare(strict_types=1); namespace App\Controller; use Ruwork\ManualAuthBundle\ManualAuthTokens; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\Form\FormInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\User\UserInterface; final class RegistrationController { private $manualAuthTokens; public function __construct(ManualAuthTokens $manualAuthTokens) { $this->manualAuthTokens = $manualAuthTokens; } /** * @Route("/registration") */ public function __invoke() { // registration form handling /** * @var UserInterface $user * @var FormInterface $form */ if ($form->isSubmitted() && $form->isValid()) { // save user // you have to create a relevant token // f.e. PostAuthGuardToken for a firewall with guard authentication $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles()); $this->manualAuthTokens->set('main', $token); // redirect to next page } // not submitted and invalid form logic } }