/** * Create a new token with the provided payload * * The default algorithm used is HS256. To set a custom one, set * the env variable JWT_ALGO. * * @todo Support for enforcing required claims in payload as well as defaults * * @param JwtPayloadInterface|array $payload * @param string|null $secret * @param string|null $algo * * @return JwtToken */ public function createToken($payload, $secret = null, $algo = null) { $algo = $algo ?: $this->algorithm(); $secret = $secret ?: $this->secret(); if ($payload instanceof JwtPayloadInterface) { $payload = $payload->getPayload(); } $newToken = $this->jwt->createToken($payload, $secret, $algo); $token = clone $this; $token->setToken($newToken); return $token; }
public function it_gets_the_payload_data_from_the_provided_dot_path(JwtDriverInterface $jwt) { $jwt->decodeToken('token_123', 'secret_123', 'HS256')->willReturn(['foo' => 'bar', 'context' => ['some' => 'data']]); $this->setToken('token_123'); $this->payload('foo')->shouldReturn('bar'); $this->payload('context')->shouldReturn(['some' => 'data']); $this->payload('context.some')->shouldReturn('data'); }