PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backwpup/vendor/WindowsAzure/Common/Internal/Authentication/OAuthScheme.php

https://gitlab.com/pankajmohale/chef2go
PHP | 142 lines | 50 code | 13 blank | 79 comment | 3 complexity | 5205cb5e58799cccbe7414bf8da414f5 MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package WindowsAzure\Common\Internal\Authentication
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link http://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Common\Internal\Authentication;
  24. use WindowsAzure\Common\Internal\Authentication\IAuthScheme;
  25. use WindowsAzure\Common\Internal\Resources;
  26. use WindowsAzure\Common\Internal\Utilities;
  27. use WindowsAzure\Common\Internal\Validate;
  28. use WindowsAzure\Common\Internal\OAuthRestProxy;
  29. use WindowsAzure\Common\Models\OAuthAccessToken;
  30. /**
  31. * Provides shared key authentication scheme for OAuth.
  32. *
  33. * @category Microsoft
  34. * @package WindowsAzure\Common\Internal\Authentication
  35. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  36. * @copyright Microsoft Corporation
  37. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  38. * @version Release: 0.4.1_2015-03
  39. * @link http://github.com/windowsazure/azure-sdk-for-php
  40. */
  41. class OAuthScheme implements IAuthScheme
  42. {
  43. /**
  44. * @var string
  45. */
  46. protected $accountName;
  47. /**
  48. * @var string
  49. */
  50. protected $accountKey;
  51. /**
  52. * @var WindowsAzure\Common\Models\OAuthAccessToken
  53. */
  54. protected $accessToken;
  55. /**
  56. * @var WindowsAzure\Common\Internal\OAuthRestProxy
  57. */
  58. protected $oauthService;
  59. /**
  60. * @var string
  61. */
  62. protected $grantType;
  63. /**
  64. * @var string
  65. */
  66. protected $scope;
  67. /**
  68. * Constructor.
  69. *
  70. * @param string $accountName account name.
  71. * @param string $accountKey account
  72. * secondary key.
  73. *
  74. * @param string $grantType grant type
  75. * for OAuth request.
  76. *
  77. * @param string $scope scope for
  78. * OAurh request.
  79. *
  80. * @param WindowsAzure\Common\Internal\OAuthRestProxy $oauthService account
  81. * primary or secondary key.
  82. */
  83. public function __construct(
  84. $accountName,
  85. $accountKey,
  86. $grantType,
  87. $scope,
  88. $oauthService
  89. ) {
  90. Validate::isString($accountName, 'accountName');
  91. Validate::isString($accountKey, 'accountKey');
  92. Validate::isString($grantType, 'grantType');
  93. Validate::isString($scope, 'scope');
  94. Validate::notNull($oauthService, 'oauthService');
  95. $this->accountName = $accountName;
  96. $this->accountKey = $accountKey;
  97. $this->grantType = $grantType;
  98. $this->scope = $scope;
  99. $this->oauthService = $oauthService;
  100. }
  101. /**
  102. * Returns authorization header to be included in the request.
  103. *
  104. * @param array $headers request headers.
  105. * @param string $url reuqest url.
  106. * @param array $queryParams query variables.
  107. * @param string $httpMethod request http method.
  108. *
  109. * @see Specifying the Authorization Header section at
  110. * http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
  111. *
  112. * @return string
  113. */
  114. public function getAuthorizationHeader($headers, $url, $queryParams, $httpMethod)
  115. {
  116. if (($this->accessToken == null)
  117. || ($this->accessToken->getExpiresIn() < time())
  118. ) {
  119. $this->accessToken = $this->oauthService->getAccessToken(
  120. $this->grantType,
  121. $this->accountName,
  122. $this->accountKey,
  123. $this->scope
  124. );
  125. }
  126. return Resources::OAUTH_ACCESS_TOKEN_PREFIX .
  127. $this->accessToken->getAccessToken();
  128. }
  129. }