/** * Test User encode to JWT and decode from JWT back. */ public function testUserEncodeDecode() { $users = User::all(); $this->assertGreaterThan(0, count($users)); /** @var User $firstUser */ $this->assertNotNull($firstUser = $users[0]); unset($users); $this->assertNotNull($jwt = $this->codec->encode($firstUser)); $this->assertNotNull($sameUser = $this->codec->decode($jwt)); $this->assertEquals($firstUser->getAuthIdentifier(), $sameUser->getAuthIdentifier()); }
/** * Create a new filter instance. * * @param IntegrationInterface $integration * @param UserJwtCodecInterface $codec * @param AuthInterface $auth */ public function __construct(IntegrationInterface $integration, UserJwtCodecInterface $codec, AuthInterface $auth) { $authenticateClosure = function ($jwt) use($codec, $auth) { $isAuthenticated = false; if (($user = $codec->decode($jwt)) !== null) { $auth->login($user); $isAuthenticated = true; } return $isAuthenticated; }; /** @var Closure|null $authorizeClosure */ $authorizeClosure = null; /** @var string|null $realm */ $realm = null; parent::__construct($integration, $authenticateClosure, $authorizeClosure, $realm); }