/** * @covers ::getEncoded */ public function testSpecifyingEncodingKeyProducesCorrectOutput() { $expected = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6M30.eyJ1c2VyI' . 'joiRm9vIEJhciJ9.E2gekVU0lErEsIqIWSdG7-32yVhALHr_tZu5DFfWVjM'; $keys = (new KeyContainer())->addKey(3, Algorithm::HMAC_SHA_256(), new Secret('secret'))->addKey(1, Algorithm::HMAC_SHA_384(), new Secret('xxx'))->addKey(2, Algorithm::HMAC_SHA_512(), new Secret('yyy')); $jwt = new JWT(['user' => 'Foo Bar']); $jwt->setKeys($keys); $this->assertSame($expected, $jwt->getEncoded(3), 'Encoded output did not match expected'); }
public function getEncodedToken() : string { if (!$this->keys) { throw new BadMethodCallException('call setKeys() before getEncodedToken()'); } $jwt = new JWT($this->getDataForJWT()); $jwt->setKeys($this->keys); return $jwt->getEncoded(); }