Ejemplo n.º 1
0
 /**
  * getToken.
  *
  * @return JwtToken
  */
 public function getJwtToken()
 {
     if ($this->token && $this->token->isValid()) {
         return $this->token;
     }
     $url = $this->options['token_url'];
     $requestOptions = array_merge($this->getDefaultHeaders(), $this->auth->getRequestOptions());
     $response = $this->client->request('POST', $url, $requestOptions);
     $body = json_decode($response->getBody(), true);
     $expiresIn = isset($body[$this->options['expire_key']]) ? $body[$this->options['expire_key']] : null;
     if ($expiresIn) {
         $expiration = new \DateTime('now + ' . $expiresIn . ' seconds');
     } else {
         $expiration = null;
     }
     $this->token = new JwtToken($body[$this->options['token_key']], $expiration);
     return $this->token;
 }
Ejemplo n.º 2
0
 public function testTokenShouldBeValidIfExpirationIsInTheFuture()
 {
     $token = new JwtToken('foo', new \DateTime('now + 5 minutes'));
     $this->assertTrue($token->isValid());
 }