示例#1
0
 /**
  * Returns authorization header to be included in the request.
  *
  * @param array  $headers     request headers.
  * @param string $url         reuqest url.
  * @param array  $queryParams query variables.
  * @param string $httpMethod  request http method.
  *
  * @see Specifying the Authorization Header section at
  *      http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
  *
  * @return string
  */
 public function getAuthorizationHeader($headers, $url, $queryParams, $httpMethod)
 {
     if ($this->accessToken == null || $this->accessToken->getExpiresIn() < time()) {
         $this->accessToken = $this->oauthService->getAccessToken($this->grantType, $this->accountName, $this->accountKey, $this->scope);
     }
     return Resources::OAUTH_ACCESS_TOKEN_PREFIX . $this->accessToken->getAccessToken();
 }
 /**
  * @covers WindowsAzure\Common\Internal\OAuthRestProxy::getAccessToken
  * @covers WindowsAzure\Common\Internal\OAuthRestProxy::__construct
  */
 public function testGetAccessToken()
 {
     // Setup
     $channel = new HttpClient();
     $uri = Resources::MEDIA_SERVICES_OAUTH_URL;
     $connection = TestResources::getMediaServicesConnectionParameters();
     $settings = new MediaServicesSettings($connection['accountName'], $connection['accessKey']);
     $scope = Resources::MEDIA_SERVICES_OAUTH_SCOPE;
     // Test
     $proxy = new OAuthRestProxy($channel, $uri);
     $actual = $proxy->getAccessToken(Resources::OAUTH_GT_CLIENT_CREDENTIALS, $settings->getAccountName(), $settings->getAccessKey(), $scope);
     // Assert
     $this->assertNotNull($proxy);
     $this->assertNotNull($actual->getAccessToken());
     $this->assertGreaterThan(time(), $actual->getExpiresIn());
     $this->assertEquals($scope, $actual->getScope());
 }