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

https://github.com/Canuckaholic/Pop-Digital · PHP · 118 lines · 57 code · 13 blank · 48 comment · 0 complexity · d215984d0074a9e0b8e4d98ccedb4fa8 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
  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 https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Common\Internal;
  24. use WindowsAzure\Common\Internal\Resources;
  25. use WindowsAzure\Common\Internal\ServiceRestProxy;
  26. use WindowsAzure\Common\Models\OAuthAccessToken;
  27. use WindowsAzure\Common\Internal\Serialization\JsonSerializer;
  28. /**
  29. * OAuth rest proxy.
  30. *
  31. * @category Microsoft
  32. * @package WindowsAzure\Common\Internal
  33. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  34. * @copyright Microsoft Corporation
  35. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  36. * @version Release: 0.4.0_2014-01
  37. * @link https://github.com/windowsazure/azure-sdk-for-php
  38. */
  39. class OAuthRestProxy extends ServiceRestProxy
  40. {
  41. /**
  42. * Initializes new OAuthRestProxy object.
  43. *
  44. * @param IHttpClient $channel The HTTP client used to send HTTP requests.
  45. * @param string $uri The storage account uri.
  46. */
  47. public function __construct($channel, $uri)
  48. {
  49. parent::__construct(
  50. $channel,
  51. $uri,
  52. Resources::EMPTY_STRING,
  53. new JsonSerializer()
  54. );
  55. }
  56. /**
  57. * Get OAuth access token.
  58. *
  59. * @param string $grantType OAuth request grant_type field value.
  60. * @param string $clientId OAuth request clent_id field value.
  61. * @param string $clientSecret OAuth request clent_secret field value.
  62. * @param string $scope OAuth request scope field value.
  63. *
  64. * @return WindowsAzure\Common\Internal\Models\OAuthAccessToken
  65. */
  66. public function getAccessToken($grantType, $clientId, $clientSecret, $scope)
  67. {
  68. $method = Resources::HTTP_POST;
  69. $headers = array();
  70. $queryParams = array();
  71. $postParameters = array();
  72. $statusCode = Resources::STATUS_OK;
  73. $postParameters = $this->addPostParameter(
  74. $postParameters,
  75. Resources::OAUTH_GRANT_TYPE,
  76. $grantType
  77. );
  78. $postParameters = $this->addPostParameter(
  79. $postParameters,
  80. Resources::OAUTH_CLIENT_ID,
  81. $clientId
  82. );
  83. $postParameters = $this->addPostParameter(
  84. $postParameters,
  85. Resources::OAUTH_CLIENT_SECRET,
  86. $clientSecret
  87. );
  88. $postParameters = $this->addPostParameter(
  89. $postParameters,
  90. Resources::OAUTH_SCOPE,
  91. $scope
  92. );
  93. $response = $this->send(
  94. $method,
  95. $headers,
  96. $queryParams,
  97. $postParameters,
  98. Resources::EMPTY_STRING,
  99. $statusCode
  100. );
  101. return OAuthAccessToken::create(
  102. $this->dataSerializer->unserialize($response->getBody())
  103. );
  104. }
  105. }