コード例 #1
0
ファイル: TokenTest.php プロジェクト: tubepress/tubepress
 public function testIsExpired()
 {
     $inTheFuture = time() + 200;
     $this->_sut->setEndOfLifeUnixTime($inTheFuture);
     $this->assertFalse($this->_sut->isExpired());
     $inThePast = time() - 200;
     $this->_sut->setEndOfLifeUnixTime($inThePast);
     $this->assertTrue($this->_sut->isExpired());
     $now = time();
     $this->_sut->setEndOfLifeUnixTime($now);
     $this->assertFalse($this->_sut->isExpired());
     $then = time() + 200;
     $this->_sut->setLifetimeInSeconds(200);
     $this->assertFalse($this->_sut->isExpired());
     $this->assertEquals($then, $this->_sut->getEndOfLifeUnixTime());
 }
コード例 #2
0
 private function _buildTokenFromResponse(tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider, tubepress_api_http_message_ResponseInterface $response)
 {
     $body = $response->getBody()->toString();
     $decoded = json_decode($body, true);
     if (!is_array($decoded)) {
         throw new RuntimeException(sprintf('%s returned invalid JSON in their access token response', $provider->getDisplayName()));
     }
     if (!isset($decoded['access_token'])) {
         throw new RuntimeException(sprintf('%s did not return an access token in their response', $provider->getDisplayName()));
     }
     if ($provider->getAccessTokenType() != '' && !isset($decoded['token_type'])) {
         throw new RuntimeException(sprintf('%s did not return a token type in their response', $provider->getDisplayName()));
     }
     $tokenType = $decoded['token_type'];
     if ($tokenType !== $provider->getAccessTokenType()) {
         throw new RuntimeException(sprintf('%s should have returned a token type of %s but instead returned %s', $provider->getDisplayName(), $provider->getAccessTokenType(), $tokenType));
     }
     $toReturn = new tubepress_http_oauth2_impl_token_Token();
     $toReturn->setAccessToken($decoded['access_token']);
     if (isset($decoded['expires_in'])) {
         $toReturn->setLifetimeInSeconds(intval($decoded['expires_in']));
     }
     if (isset($decoded['refresh_token'])) {
         $toReturn->setRefreshToken($decoded['refresh_token']);
     }
     $keysToFilter = array('access_token', 'expires_in', 'refresh_token');
     $extraParams = array_diff_key($decoded, array_flip($keysToFilter));
     $toReturn->setExtraParams($extraParams);
     return $toReturn;
 }