Ejemplo n.º 1
0
 public function testIsExpired()
 {
     $expiredJwt = JWT::fromString($this->expiredToken);
     $this->assertTrue($expiredJwt->isExpired());
     $validJwt = JWT::fromString($this->neverExpiredToken);
     $this->assertFalse($validJwt->isExpired());
 }
Ejemplo n.º 2
0
 /**
  * @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());
     }
 }