/** * @covers WindowsAzure\ServiceBus\Internal\ActiveToken::getExpirationDateTime * @covers WindowsAzure\ServiceBus\Internal\ActiveToken::setExpirationDateTime */ public function testActiveTokenGetSetExpirationDateTimeResult() { // Setup $expected = new \DateTime(); $wrapAccessTokenResult = new WrapAccessTokenResult(); // Test $activeToken = new ActiveToken($wrapAccessTokenResult); $activeToken->setExpirationDateTime($expected); $actual = $activeToken->getExpirationDateTime(); // Assert $this->assertEquals($expected, $actual); }
/** * Gets WRAP access token with sepcified target Uri. * * @param string $targetUri The target Uri of the WRAP access Token. * * @return string */ public function getAccessToken($targetUri) { Validate::isString($targetUri, '$targetUri'); $this->_sweepExpiredTokens(); $scopeUri = $this->_createScopeUri($targetUri); if (array_key_exists($scopeUri, $this->_activeTokens)) { $activeToken = $this->_activeTokens[$scopeUri]; return $activeToken->getWrapAccessTokenResult()->getAccessToken(); } $wrapAccessTokenResult = $this->_wrapRestProxy->wrapAccessToken($this->_wrapUri, $this->_wrapName, $this->_wrapPassword, $scopeUri); $expirationDateTime = new \DateTime("now"); $expiresIn = intval($wrapAccessTokenResult->getExpiresIn() / 2); $expirationDateTime = $expirationDateTime->add(new \DateInterval('PT' . $expiresIn . 'S')); $acquiredActiveToken = new ActiveToken($wrapAccessTokenResult); $acquiredActiveToken->setExpirationDateTime($expirationDateTime); $this->_activeTokens[$scopeUri] = $acquiredActiveToken; return $wrapAccessTokenResult->getAccessToken(); }