public function testIsExpired() { $expiredJwt = JWT::fromString($this->expiredToken); $this->assertTrue($expiredJwt->isExpired()); $validJwt = JWT::fromString($this->neverExpiredToken); $this->assertFalse($validJwt->isExpired()); }
/** * @param string $username Username * @param string $password Password * @param array $config Guzzle client configuration settings * * @return AuthenticatedApiClient */ public static function authenticate($username, $password, array $config = []) { $client = new Client(['base_uri' => AuthenticatedApiClient::API_URL]); try { $authResponse = $client->post('/api/login_check', ['json' => ['username' => $username, 'password' => $password]]); $jsonResponse = json_decode($authResponse->getBody(), true); $jwt = JWT::fromString($jsonResponse['token']); $client = new AuthenticatedApiClient($jwt, $config); return $client; } catch (RequestException $e) { throw new AuthenticationException('Authentication problem', $e->getRequest(), $e->getResponse()); } }