diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-06 06:41:47 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-06 06:41:47 -0500 |
commit | c80c15dcc33a70acc2b177691d33f088f8c2541e (patch) | |
tree | bc3e44e35b97b751c145cc5797a0faf356922244 /vendor/lusitanian/oauth/src/OAuth/Common/Service | |
parent | c91ff61cdfa8b5eb76783927e5b8710f2a9f2601 (diff) |
Include all vendor files in the repo to be easier for people
Diffstat (limited to 'vendor/lusitanian/oauth/src/OAuth/Common/Service')
-rw-r--r-- | vendor/lusitanian/oauth/src/OAuth/Common/Service/AbstractService.php | 100 | ||||
-rw-r--r-- | vendor/lusitanian/oauth/src/OAuth/Common/Service/ServiceInterface.php | 49 |
2 files changed, 149 insertions, 0 deletions
diff --git a/vendor/lusitanian/oauth/src/OAuth/Common/Service/AbstractService.php b/vendor/lusitanian/oauth/src/OAuth/Common/Service/AbstractService.php new file mode 100644 index 00000000..0bf572b4 --- /dev/null +++ b/vendor/lusitanian/oauth/src/OAuth/Common/Service/AbstractService.php @@ -0,0 +1,100 @@ +<?php + +namespace OAuth\Common\Service; + +use OAuth\Common\Consumer\CredentialsInterface; +use OAuth\Common\Http\Client\ClientInterface; +use OAuth\Common\Http\Uri\Uri; +use OAuth\Common\Http\Uri\UriInterface; +use OAuth\Common\Exception\Exception; +use OAuth\Common\Storage\TokenStorageInterface; + +/** + * Abstract OAuth service, version-agnostic + */ +abstract class AbstractService implements ServiceInterface +{ + /** @var Credentials */ + protected $credentials; + + /** @var ClientInterface */ + protected $httpClient; + + /** @var TokenStorageInterface */ + protected $storage; + + /** + * @param CredentialsInterface $credentials + * @param ClientInterface $httpClient + * @param TokenStorageInterface $storage + */ + public function __construct( + CredentialsInterface $credentials, + ClientInterface $httpClient, + TokenStorageInterface $storage + ) { + $this->credentials = $credentials; + $this->httpClient = $httpClient; + $this->storage = $storage; + } + + /** + * @param UriInterface|string $path + * @param UriInterface $baseApiUri + * + * @return UriInterface + * + * @throws Exception + */ + protected function determineRequestUriFromPath($path, UriInterface $baseApiUri = null) + { + if ($path instanceof UriInterface) { + $uri = $path; + } elseif (stripos($path, 'http://') === 0 || stripos($path, 'https://') === 0) { + $uri = new Uri($path); + } else { + if (null === $baseApiUri) { + throw new Exception( + 'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set.' + ); + } + + $uri = clone $baseApiUri; + if (false !== strpos($path, '?')) { + $parts = explode('?', $path, 2); + $path = $parts[0]; + $query = $parts[1]; + $uri->setQuery($query); + } + + if ($path[0] === '/') { + $path = substr($path, 1); + } + + $uri->setPath($uri->getPath() . $path); + } + + return $uri; + } + + /** + * Accessor to the storage adapter to be able to retrieve tokens + * + * @return TokenStorageInterface + */ + public function getStorage() + { + return $this->storage; + } + + /** + * @return string + */ + public function service() + { + // get class name without backslashes + $classname = get_class($this); + + return preg_replace('/^.*\\\\/', '', $classname); + } +} diff --git a/vendor/lusitanian/oauth/src/OAuth/Common/Service/ServiceInterface.php b/vendor/lusitanian/oauth/src/OAuth/Common/Service/ServiceInterface.php new file mode 100644 index 00000000..5856a039 --- /dev/null +++ b/vendor/lusitanian/oauth/src/OAuth/Common/Service/ServiceInterface.php @@ -0,0 +1,49 @@ +<?php + +namespace OAuth\Common\Service; + +use OAuth\Common\Http\Uri\UriInterface; + +/** + * Defines methods common among all OAuth services. + */ +interface ServiceInterface +{ + /** + * Sends an authenticated API request to the path provided. + * If the path provided is not an absolute URI, the base API Uri (service-specific) will be used. + * + * @param string|UriInterface $path + * @param string $method HTTP method + * @param array $body Request body if applicable (an associative array will + * automatically be converted into a urlencoded body) + * @param array $extraHeaders Extra headers if applicable. These will override service-specific + * any defaults. + * + * @return string + */ + public function request($path, $method = 'GET', $body = null, array $extraHeaders = array()); + + /** + * Returns the url to redirect to for authorization purposes. + * + * @param array $additionalParameters + * + * @return UriInterface + */ + public function getAuthorizationUri(array $additionalParameters = array()); + + /** + * Returns the authorization API endpoint. + * + * @return UriInterface + */ + public function getAuthorizationEndpoint(); + + /** + * Returns the access token API endpoint. + * + * @return UriInterface + */ + public function getAccessTokenEndpoint(); +} |