vendor/zely/security-bundle/src/TokenHandler.php line 19

  1. <?php
  2. namespace Zely\Security;
  3. use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  4. use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
  5. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
  6. class TokenHandler implements AccessTokenHandlerInterface
  7. {
  8.     public function getUserBadgeFrom(string $accessToken): UserBadge
  9.     {
  10.         if (!$accessToken) {
  11.             throw new BadCredentialsException('Invalid credentials.');
  12.         }
  13.         $parts explode("||"$accessToken);
  14.         $tActor $parts[1];
  15.         // and return a UserBadge object containing the user identifier from the found token
  16.         return new UserBadge($tActor, function ($id) use ($parts) {
  17.             $tEmail $parts[2];
  18.             $tRoles explode(",",$parts[3]);
  19.             $tRoles array_filter($tRoles, function ($r) {
  20.                 return $r;
  21.             });
  22.             return (new User($id$tRolestrue))
  23.                 ->setEmail($tEmail);
  24.         });
  25.     }
  26. }