use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authorization\Voter\RoleHierarchyVoter; use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; use Symfony\Component\Security\Http\Firewall\Listener\UserAuthenticationListener; $encoder = new MessageDigestPasswordEncoder(); $authProvider = new DaoAuthenticationProvider($userProvider, $userChecker, 'secured_area', $encoder); $authManager = new AccessDecisionManager(array(new RoleHierarchyVoter($roleHierarchy))); $tokenStorage = new TokenStorage(); $userListener = new UserAuthenticationListener($tokenStorage, $authProvider, 'secured_area', $logger, $authManager); $auth = $userListener->getAuthenticator();
use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\UserProvider; class SessionGuard implements Guard { ... protected function createResponse($token) { $user = $this->userProvider->retrieveById($token['userId']); $this->storeUserWithRememberMe($user, $token['token'], $token['expires']); return new SessionGuardResponse($user->getAuthIdentifier()); } ... } $auth = Auth::getInstance(new UserProvider(), new SessionGuard(), new ThrottleProvider(), new SessionManager());Package Library: The package library used in these examples is PHP's authentication library. However, the specific implementation of the library depends on the authentication library used, such as Symfony's Security component or Laravel's Authentication library.