diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-11-17 20:45:02 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-11-17 20:45:02 +0100 |
commit | 8df3db566a3a937b45ebf11adb90d265e6f5e2d4 (patch) | |
tree | 4d541098d751d5a9acf8c12f6fb9f308ace066ac /vendor/league/oauth2-client | |
download | flyspray-8df3db566a3a937b45ebf11adb90d265e6f5e2d4.tar.xz |
initial checking of customized version 1.0rc9
Diffstat (limited to 'vendor/league/oauth2-client')
23 files changed, 2012 insertions, 0 deletions
diff --git a/vendor/league/oauth2-client/CHANGELOG.md b/vendor/league/oauth2-client/CHANGELOG.md new file mode 100644 index 0000000..97e27c5 --- /dev/null +++ b/vendor/league/oauth2-client/CHANGELOG.md @@ -0,0 +1,154 @@ +# OAuth 2.0 Client Changelog + +## 0.12.1 + +_Released: 2015-06-20_ + +* FIX: Scope separators for LinkedIn and Instagram are now correctly a single space + +## 0.12.0 + +_Released: 2015-06-15_ + +* BREAK: LinkedIn Provider: Default scopes removed from LinkedIn Provider. See "[Managing LinkedIn Scopes](https://github.com/thephpleague/oauth2-client/blob/9cea9864c2e89bce1b922d1e37ba5378b3b0b264/README.md#managing-linkedin-scopes)" in the README for information on how to set scopes. See [#327](https://github.com/thephpleague/oauth2-client/pull/327) and [#307](https://github.com/thephpleague/oauth2-client/pull/307) for details on this change. +* FIX: LinkedIn Provider: A scenario existed in which `publicProfileUrl` was not set, generating a PHP notice; this has been fixed. +* FIX: Instagram Provider: Fixed scope separator. +* Documentation updates and corrections. + + +## 0.11.0 + +_Released: 2015-04-25_ + +* Identity Provider: Better handling of error responses +* Documentation updates + + +## 0.10.1 + +_Released: 2015-04-02_ + +* FIX: Invalid JSON triggering fatal error +* FIX: Sending headers along with auth `getAccessToken()` requests +* Now running Travis CI tests on PHP 7 +* Documentation updates + + +## 0.10.0 + +_Released: 2015-03-10_ + +* Providers: Added `getHeaders()` to ProviderInterface and updated AbstractProvider to provide the method +* Providers: Updated all bundled providers to support new `$authorizationHeader` property +* Identity Provider: Update IDPException to account for empty strings +* Identity Provider: Added `getResponseBody()` method to IDPException +* Documentation updates, minor bug fixes, and coding standards fixes + + +## 0.9.0 + +_Released: 2015-02-24_ + +* Add `AbstractProvider::prepareAccessTokenResult()` to provide additional token response preparation to providers +* Remove custom provider code from AccessToken +* Add links to README for Dropbox and Square providers + + +## 0.8.1 + +_Released: 2015-02-12_ + +* Allow `approval_prompt` to be set by providers. This fixes an issue where some providers have problems if the `approval_prompt` is present in the query string. + + +## 0.8.0 + +_Released: 2015-02-10_ + +* Facebook Provider: Upgrade to Graph API v2.2 +* Google Provider: Add `access_type` parameter for Google authorization URL +* Get a more reliable response body on errors + + +## 0.7.2 + +_Released: 2015-02-03_ + +* GitHub Provider: Fix regression +* Documentation updates + + +## 0.7.1 + +_Released: 2015-01-06_ + +* Google Provider: fixed issue where Google API was not returning the user ID + + +## 0.7.0 + +_Released: 2014-12-29_ + +* Improvements to Provider\AbstractProvider (addition of `userUid()`, `userEmail()`, and `userScreenName()`) +* GitHub Provider: Support for GitHub Enterprise +* GitHub Provider: Methods to allow fetching user email addresses +* Google Provider: Updated scopes and endpoints to remove deprecated values +* Documentation updates, minor bug fixes, and coding standards fixes + + +## 0.6.0 + +_Released: 2014-12-03_ + +* Added ability to specify a redirect handler for providers through use of a callback (see [Provider\AbstractProvider::setRedirectHandler()](https://github.com/thephpleague/oauth2-client/blob/55de45401eaa21f53c0b2414091da6f3b0f3fcb7/src/Provider/AbstractProvider.php#L314-L317)) +* Updated authorize and token URLs for the Microsoft provider; the old URLs had been phased out and were no longer working (see #146) +* Increased test coverage +* Documentation updates, minor bug fixes, and coding standards fixes + + +## 0.5.0 + +_Released: 2014-11-28_ + +* Added `ClientCredentials` and `Password` grants +* Added support for providers to set their own `uid` parameter key name +* Added support for Google's `hd` (hosted domain) parameter +* Added support for providing a custom `state` parameter to the authorization URL +* LinkedIn `pictureUrl` is now an optional response element +* Added Battle.net provider package link to README +* Added Meetup provider package link to README +* Added `.gitattributes` file +* Increased test coverage +* A number of documentation fixes, minor bug fixes, and coding standards fixes + + +## 0.4.0 + +_Released: 2014-10-28_ + +* Added `ProviderInterface` and removed `IdentityProvider`. +* Expose generated state to allow for CSRF validation. +* Renamed `League\OAuth2\Client\Provider\User` to `League\OAuth2\Client\Entity\User`. +* Entity: User: added `gender` and `locale` properties +* Updating logic for populating the token expiration time. + + +## 0.3.0 + +_Released: 2014-04-26_ + +* This release made some huge leaps forward, including 100% unit-coverage and a bunch of new features. + + +## 0.2.0 + +_Released: 2013-05-28_ + +* No release notes available. + + +## 0.1.0 + +_Released: 2013-05-25_ + +* Initial release. diff --git a/vendor/league/oauth2-client/CONTRIBUTING.md b/vendor/league/oauth2-client/CONTRIBUTING.md new file mode 100644 index 0000000..ce73506 --- /dev/null +++ b/vendor/league/oauth2-client/CONTRIBUTING.md @@ -0,0 +1,42 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/oauth2-client). + + +## Pull Requests + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow SemVer. Randomly breaking public APIs is not an option. + +- **Create topic branches** - Don't ask us to pull from your master branch. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + +- **Ensure tests pass!** - Please run the tests (see below) before submitting your pull request, and make sure they pass. We won't accept a patch until all tests pass. + +- **Ensure no coding standards violations** - Please run PHP Code Sniffer using the PSR-2 standard (see below) before submitting your pull request. A violation will cause the build to fail, so please make sure there are no violations. We can't accept a patch if the build fails. + + +## Running Tests + +``` bash +$ ./vendor/bin/phpunit +``` + + +## Running PHP Code Sniffer + +``` bash +$ ./vendor/bin/phpcs src --standard=psr2 -sp +``` + +**Happy coding**! diff --git a/vendor/league/oauth2-client/LICENSE b/vendor/league/oauth2-client/LICENSE new file mode 100644 index 0000000..b71bd59 --- /dev/null +++ b/vendor/league/oauth2-client/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Alex Bilbie <hello@alexbilbie.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/league/oauth2-client/README.md b/vendor/league/oauth2-client/README.md new file mode 100644 index 0000000..0b55d60 --- /dev/null +++ b/vendor/league/oauth2-client/README.md @@ -0,0 +1,247 @@ +# OAuth 2.0 Client + +[![Join the chat at https://gitter.im/thephpleague/oauth2-client](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/thephpleague/oauth2-client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +[![Build Status](https://travis-ci.org/thephpleague/oauth2-client.svg?branch=master)](https://travis-ci.org/thephpleague/oauth2-client) +[![Coverage Status](https://coveralls.io/repos/thephpleague/oauth2-client/badge.svg?branch=master)](https://coveralls.io/r/thephpleague/oauth2-client?branch=master) +[![Latest Stable Version](https://poser.pugx.org/league/oauth2-client/v/stable)](https://packagist.org/packages/league/oauth2-client) +[![Total Downloads](https://poser.pugx.org/league/oauth2-client/downloads)](https://packagist.org/packages/league/oauth2-client) +[![Latest Unstable Version](https://poser.pugx.org/league/oauth2-client/v/unstable)](https://packagist.org/packages/league/oauth2-client) +[![License](https://poser.pugx.org/league/oauth2-client/license)](https://packagist.org/packages/league/oauth2-client) + +This package makes it stupidly simple to integrate your application with OAuth 2.0 identity providers. + +Everyone is used to seeing those "Connect with Facebook/Google/etc" buttons around the Internet and social network +integration is an important feature of most web-apps these days. Many of these sites use an Authentication and Authorization standard called OAuth 2.0. + +It will work with any OAuth 2.0 provider (be it an OAuth 2.0 Server for your own API or Facebook) and provides support +for popular systems out of the box. This package abstracts out some of the subtle but important differences between various providers, handles access tokens and refresh tokens, and allows you easy access to profile information on these other sites. + +This package is compliant with [PSR-1][], [PSR-2][] and [PSR-4][]. If you notice compliance oversights, please send +a patch via pull request. + +[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md +[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md +[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md + + +## Requirements + +The following versions of PHP are supported. + +* PHP 5.4 +* PHP 5.5 +* PHP 5.6 +* PHP 7.0 +* HHVM + +## Usage + +### Authorization Code Flow + +*Note: This example code requires the Google+ API to be enabled in your developer console* + +```php +$provider = new League\OAuth2\Client\Provider\<ProviderName>([ + 'clientId' => 'XXXXXXXX', + 'clientSecret' => 'XXXXXXXX', + 'redirectUri' => 'https://your-registered-redirect-uri/', + 'scopes' => ['email', '...', '...'], +]); + +if (!isset($_GET['code'])) { + + // If we don't have an authorization code then get one + $authUrl = $provider->getAuthorizationUrl(); + $_SESSION['oauth2state'] = $provider->state; + header('Location: '.$authUrl); + exit; + +// Check given state against previously stored one to mitigate CSRF attack +} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { + + unset($_SESSION['oauth2state']); + exit('Invalid state'); + +} else { + + // Try to get an access token (using the authorization code grant) + $token = $provider->getAccessToken('authorization_code', [ + 'code' => $_GET['code'] + ]); + + // Optional: Now you have a token you can look up a users profile data + try { + + // We got an access token, let's now get the user's details + $userDetails = $provider->getUserDetails($token); + + // Use these details to create a new profile + printf('Hello %s!', $userDetails->firstName); + + } catch (Exception $e) { + + // Failed to get user details + exit('Oh dear...'); + } + + // Use this to interact with an API on the users behalf + echo $token->accessToken; + + // Use this to get a new access token if the old one expires + echo $token->refreshToken; + + // Unix timestamp of when the token will expire, and need refreshing + echo $token->expires; +} +``` + +### Refreshing a Token + +Once and as long as your application is authorized, you then only need to refresh an expired access token. To do so, simply reuse this refresh token from your data store to request a refresh. + +```php +$provider = new League\OAuth2\Client\Provider\<ProviderName>([ + 'clientId' => 'XXXXXXXX', + 'clientSecret' => 'XXXXXXXX', + 'redirectUri' => 'https://your-registered-redirect-uri/', +]); + +$grant = new \League\OAuth2\Client\Grant\RefreshToken(); +$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]); +``` + + +### Built-In Providers + +This package currently has built-in support for: + +- Eventbrite +- Facebook +- Github +- Google +- Instagram +- LinkedIn +- Microsoft + +These are as many OAuth 2 services as we plan to support officially. Maintaining a wide selection of providers +damages our ability to make this package the best it can be, especially as we progress towards v1.0. + +#### Managing LinkedIn Scopes + +The LinkedIn provider included in this package does not include scopes by default. When creating your LinkedIn provider, you can specify the scopes your application may authorize. + +```php +$provider = new League\OAuth2\Client\Provider\LinkedIn([ + 'clientId' => '{linkedin-client-id}', + 'clientSecret' => '{linkedin-client-secret}', + 'redirectUri' => 'https://example.com/callback-url', + 'scopes' => ['r_basicprofile','r_emailaddress'], +]); +``` + +At the time of authoring this documentation, the following scopes are available. + +- r_basicprofile +- r_emailaddress +- rw_company_admin +- w_share + +### Third-Party Providers + +If you would like to support other providers, please make them available as a Composer package, then link to them +below. + +These providers allow integration with other providers not supported by `oauth2-client`. They may require an older version +so please help them out with a pull request if you notice this. + +- [Amazon](https://github.com/lemonstand/oauth2-amazon/) +- [Auth0](https://github.com/RiskioFr/oauth2-auth0) +- [Battle.net](https://packagist.org/packages/depotwarehouse/oauth2-bnet) +- [BookingSync](https://github.com/BookingSync/oauth2-bookingsync-php) +- [Clover](https://github.com/wheniwork/oauth2-clover) +- [Coinbase](https://github.com/openclerk/coinbase-oauth2) +- [Dropbox](https://github.com/pixelfear/oauth2-dropbox) +- [FreeAgent](https://github.com/CloudManaged/oauth2-freeagent) +- [Google Nest](https://github.com/JC5/nest-oauth2-provider) +- [Mail.ru](https://packagist.org/packages/aego/oauth2-mailru) +- [Meetup](https://github.com/howlowck/meetup-oauth2-provider) +- [Naver](https://packagist.org/packages/deminoth/oauth2-naver) +- [Odnoklassniki](https://packagist.org/packages/aego/oauth2-odnoklassniki) +- [Reddit](https://github.com/rtheunissen/oauth2-reddit) +- [Square](https://packagist.org/packages/wheniwork/oauth2-square) +- [Twitch.tv](https://github.com/tpavlek/oauth2-twitch) +- [Uber](https://github.com/stevenmaguire/oauth2-uber) +- [Vend](https://github.com/wheniwork/oauth2-vend) +- [Vkontakte](https://packagist.org/packages/j4k/oauth2-vkontakte) +- [Yandex](https://packagist.org/packages/aego/oauth2-yandex) +- [ZenPayroll](https://packagist.org/packages/wheniwork/oauth2-zenpayroll) +- [Envato](https://github.com/dilab/envato-oauth2-provider) + +### Implementing your own provider + +If you are working with an oauth2 service not supported out-of-the-box or by an existing package, it is quite simple to +implement your own. Simply extend `League\OAuth2\Client\Provider\AbstractProvider` and implement the required abstract +methods: + +```php +abstract public function urlAuthorize(); +abstract public function urlAccessToken(); +abstract public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token); +abstract public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token); +``` + +Each of these abstract methods contain a docblock defining their expectations and typical behaviour. Once you have +extended this class, you can simply follow the example above using your new `Provider`. + +#### Custom account identifiers in access token responses + +Some OAuth2 Server implementations include a field in their access token response defining some identifier +for the user account that just requested the access token. In many cases this field, if present, is called "uid", but +some providers define custom identifiers in their response. If your provider uses a nonstandard name for the "uid" field, +when extending the AbstractProvider, in your new class, define a property `public $uidKey` and set it equal to whatever +your provider uses as its key. For example, Battle.net uses `accountId` as the key for the identifier field, so in that +provider you would add a property: + +```php +public $uidKey = 'accountId'; +``` + +### Client Packages + +Some developers use this library as a base for their own PHP API wrappers, and that seems like a really great idea. It might make it slightly tricky to integrate their provider with an existing generic "OAuth 2.0 All the Things" login system, but it does make working with them easier. + +- [Sniply](https://github.com/younes0/sniply) + +## Install + +Via Composer + +``` bash +$ composer require league/oauth2-client +``` + +## Testing + +``` bash +$ ./vendor/bin/phpunit +``` + +## Contributing + +Please see [CONTRIBUTING](https://github.com/thephpleague/oauth2-client/blob/master/CONTRIBUTING.md) for details. + + +## Credits + +- [Alex Bilbie](https://github.com/alexbilbie) +- [Ben Corlett](https://github.com/bencorlett) +- [James Mills](https://github.com/jamesmills) +- [Phil Sturgeon](https://github.com/philsturgeon) +- [Tom Anderson](https://github.com/TomHAnderson) +- [All Contributors](https://github.com/thephpleague/oauth2-client/contributors) + + +## License + +The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth2-client/blob/master/LICENSE) for more information. diff --git a/vendor/league/oauth2-client/composer.json b/vendor/league/oauth2-client/composer.json new file mode 100644 index 0000000..5f50502 --- /dev/null +++ b/vendor/league/oauth2-client/composer.json @@ -0,0 +1,44 @@ +{ + "name": "league/oauth2-client", + "description": "OAuth 2.0 Client Library", + "license": "MIT", + "require": { + "php": ">=5.4.0", + "guzzle/guzzle": "~3.7" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "mockery/mockery": "~0.9", + "squizlabs/php_codesniffer": "~2.0", + "satooshi/php-coveralls": "0.6.*", + "jakub-onderka/php-parallel-lint": "0.8.*" + }, + "keywords": [ + "oauth", + "oauth2", + "authorization", + "authentication", + "idp", + "identity", + "sso", + "single sign on" + ], + "authors": [ + { + "name": "Alex Bilbie", + "email": "hello@alexbilbie.com", + "homepage": "http://www.alexbilbie.com", + "role": "Developer" + } + ], + "autoload": { + "psr-4": { + "League\\OAuth2\\Client\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "League\\OAuth2\\Client\\Test\\": "test/src/" + } + } +} diff --git a/vendor/league/oauth2-client/src/Entity/User.php b/vendor/league/oauth2-client/src/Entity/User.php new file mode 100644 index 0000000..756e09a --- /dev/null +++ b/vendor/league/oauth2-client/src/Entity/User.php @@ -0,0 +1,117 @@ +<?php + +namespace League\OAuth2\Client\Entity; + +class User +{ + protected $uid; + protected $nickname; + protected $name; + protected $firstName; + protected $lastName; + protected $email; + protected $location; + protected $description; + protected $imageUrl; + protected $urls; + protected $gender; + protected $locale; + + public function __get($name) + { + if (!property_exists($this, $name)) { + throw new \OutOfRangeException(sprintf( + '%s does not contain a property by the name of "%s"', + __CLASS__, + $name + )); + } + + return $this->{$name}; + } + + public function __set($property, $value) + { + if (!property_exists($this, $property)) { + throw new \OutOfRangeException(sprintf( + '%s does not contain a property by the name of "%s"', + __CLASS__, + $property + )); + } + + $this->$property = $value; + + return $this; + } + + public function __isset($name) + { + return (property_exists($this, $name)); + } + + public function getArrayCopy() + { + return [ + 'uid' => $this->uid, + 'nickname' => $this->nickname, + 'name' => $this->name, + 'firstName' => $this->firstName, + 'lastName' => $this->lastName, + 'email' => $this->email, + 'location' => $this->location, + 'description' => $this->description, + 'imageUrl' => $this->imageUrl, + 'urls' => $this->urls, + 'gender' => $this->gender, + 'locale' => $this->locale, + ]; + } + + public function exchangeArray(array $data) + { + foreach ($data as $key => $value) { + $key = strtolower($key); + switch ($key) { + case 'uid': + $this->uid = $value; + break; + case 'nickname': + $this->nickname = $value; + break; + case 'name': + $this->name = $value; + break; + case 'firstname': + $this->firstName = $value; + break; + case 'lastname': + $this->lastName = $value; + break; + case 'email': + $this->email = $value; + break; + case 'location': + $this->location = $value; + break; + case 'description': + $this->description = $value; + break; + case 'imageurl': + $this->imageUrl = $value; + break; + case 'urls': + $this->urls = $value; + break; + case 'gender': + $this->gender = $value; + break; + case 'locale': + $this->locale = $value; + break; + } + } + + return $this; + } +} diff --git a/vendor/league/oauth2-client/src/Exception/IDPException.php b/vendor/league/oauth2-client/src/Exception/IDPException.php new file mode 100644 index 0000000..668a7e7 --- /dev/null +++ b/vendor/league/oauth2-client/src/Exception/IDPException.php @@ -0,0 +1,69 @@ +<?php + +namespace League\OAuth2\Client\Exception; + +class IDPException extends \Exception +{ + protected $result; + + public function __construct($result) + { + if (!empty($result['error']) && is_array($result['error'])) { + // Error response is wrapped in a top entity type, JSON:API style. + $result = $result['error']; + } + + $this->result = $result; + + $code = isset($result['code']) ? $result['code'] : 0; + + if (isset($result['error']) && $result['error'] !== '') { + // OAuth 2.0 Draft 10 style + $message = $result['error']; + } elseif (isset($result['message']) && $result['message'] !== '') { + // cURL style + $message = $result['message']; + } else { + $message = 'Unknown Error.'; + } + + parent::__construct($message, $code); + } + + public function getResponseBody() + { + return $this->result; + } + + public function getType() + { + $result = 'Exception'; + + if (isset($this->result['error'])) { + $message = $this->result['error']; + + if (is_string($message)) { + // OAuth 2.0 Draft 10 style + $result = $message; + } + } + + return $result; + } + + /** + * To make debugging easier. + * + * @return string The string representation of the error. + */ + public function __toString() + { + $str = $this->getType().': '; + + if ($this->code != 0) { + $str .= $this->code.': '; + } + + return $str.$this->message; + } +} diff --git a/vendor/league/oauth2-client/src/Grant/AuthorizationCode.php b/vendor/league/oauth2-client/src/Grant/AuthorizationCode.php new file mode 100644 index 0000000..bda0965 --- /dev/null +++ b/vendor/league/oauth2-client/src/Grant/AuthorizationCode.php @@ -0,0 +1,27 @@ +<?php + +namespace League\OAuth2\Client\Grant; + +use League\OAuth2\Client\Token\AccessToken; + +class AuthorizationCode implements GrantInterface +{ + public function __toString() + { + return 'authorization_code'; + } + + public function prepRequestParams($defaultParams, $params) + { + if (! isset($params['code']) || empty($params['code'])) { + throw new \BadMethodCallException('Missing authorization code'); + } + + return array_merge($defaultParams, $params); + } + + public function handleResponse($response = []) + { + return new AccessToken($response); + } +} diff --git a/vendor/league/oauth2-client/src/Grant/ClientCredentials.php b/vendor/league/oauth2-client/src/Grant/ClientCredentials.php new file mode 100644 index 0000000..7a73a79 --- /dev/null +++ b/vendor/league/oauth2-client/src/Grant/ClientCredentials.php @@ -0,0 +1,25 @@ +<?php + +namespace League\OAuth2\Client\Grant; + +use League\OAuth2\Client\Token\AccessToken; + +class ClientCredentials implements GrantInterface +{ + public function __toString() + { + return 'client_credentials'; + } + + public function prepRequestParams($defaultParams, $params) + { + $params['grant_type'] = 'client_credentials'; + + return array_merge($defaultParams, $params); + } + + public function handleResponse($response = array()) + { + return new AccessToken($response); + } +} diff --git a/vendor/league/oauth2-client/src/Grant/GrantInterface.php b/vendor/league/oauth2-client/src/Grant/GrantInterface.php new file mode 100644 index 0000000..a744ea9 --- /dev/null +++ b/vendor/league/oauth2-client/src/Grant/GrantInterface.php @@ -0,0 +1,12 @@ +<?php + +namespace League\OAuth2\Client\Grant; + +interface GrantInterface +{ + public function __toString(); + + public function handleResponse($response = []); + + public function prepRequestParams($defaultParams, $params); +} diff --git a/vendor/league/oauth2-client/src/Grant/Password.php b/vendor/league/oauth2-client/src/Grant/Password.php new file mode 100644 index 0000000..b124b34 --- /dev/null +++ b/vendor/league/oauth2-client/src/Grant/Password.php @@ -0,0 +1,33 @@ +<?php + +namespace League\OAuth2\Client\Grant; + +use League\OAuth2\Client\Token\AccessToken; + +class Password implements GrantInterface +{ + public function __toString() + { + return 'password'; + } + + public function prepRequestParams($defaultParams, $params) + { + if (! isset($params['username']) || empty($params['username'])) { + throw new \BadMethodCallException('Missing username'); + } + + if (! isset($params['password']) || empty($params['password'])) { + throw new \BadMethodCallException('Missing password'); + } + + $params['grant_type'] = 'password'; + + return array_merge($defaultParams, $params); + } + + public function handleResponse($response = array()) + { + return new AccessToken($response); + } +} diff --git a/vendor/league/oauth2-client/src/Grant/RefreshToken.php b/vendor/league/oauth2-client/src/Grant/RefreshToken.php new file mode 100644 index 0000000..86e7f6e --- /dev/null +++ b/vendor/league/oauth2-client/src/Grant/RefreshToken.php @@ -0,0 +1,29 @@ +<?php + +namespace League\OAuth2\Client\Grant; + +use League\OAuth2\Client\Token\AccessToken as AccessToken; + +class RefreshToken implements GrantInterface +{ + public function __toString() + { + return 'refresh_token'; + } + + public function prepRequestParams($defaultParams, $params) + { + if (! isset($params['refresh_token']) || empty($params['refresh_token'])) { + throw new \BadMethodCallException('Missing refresh_token'); + } + + $params['grant_type'] = 'refresh_token'; + + return array_merge($defaultParams, $params); + } + + public function handleResponse($response = []) + { + return new AccessToken($response); + } +} diff --git a/vendor/league/oauth2-client/src/Provider/AbstractProvider.php b/vendor/league/oauth2-client/src/Provider/AbstractProvider.php new file mode 100644 index 0000000..a200013 --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/AbstractProvider.php @@ -0,0 +1,399 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use Closure; +use Guzzle\Http\Exception\BadResponseException; +use Guzzle\Service\Client as GuzzleClient; +use League\OAuth2\Client\Exception\IDPException as IDPException; +use League\OAuth2\Client\Grant\GrantInterface; +use League\OAuth2\Client\Token\AccessToken as AccessToken; + +abstract class AbstractProvider implements ProviderInterface +{ + public $clientId = ''; + + public $clientSecret = ''; + + public $redirectUri = ''; + + public $state; + + public $name; + + public $uidKey = 'uid'; + + public $scopes = []; + + public $method = 'post'; + + public $scopeSeparator = ','; + + public $responseType = 'json'; + + public $headers = []; + + public $authorizationHeader; + + /** + * @var GuzzleClient + */ + protected $httpClient; + + protected $redirectHandler; + + /** + * @var int This represents: PHP_QUERY_RFC1738, which is the default value for php 5.4 + * and the default encoding type for the http_build_query setup + */ + protected $httpBuildEncType = 1; + + public function __construct($options = []) + { + foreach ($options as $option => $value) { + if (property_exists($this, $option)) { + $this->{$option} = $value; + } + } + + $this->setHttpClient(new GuzzleClient()); + } + + public function setHttpClient(GuzzleClient $client) + { + $this->httpClient = $client; + + return $this; + } + + public function getHttpClient() + { + $client = clone $this->httpClient; + + return $client; + } + + /** + * Get the URL that this provider uses to begin authorization. + * + * @return string + */ + abstract public function urlAuthorize(); + + /** + * Get the URL that this provider uses to request an access token. + * + * @return string + */ + abstract public function urlAccessToken(); + + /** + * Get the URL that this provider uses to request user details. + * + * Since this URL is typically an authorized route, most providers will require you to pass the access_token as + * a parameter to the request. For example, the google url is: + * + * 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token='.$token + * + * @param AccessToken $token + * @return string + */ + abstract public function urlUserDetails(AccessToken $token); + + /** + * Given an object response from the server, process the user details into a format expected by the user + * of the client. + * + * @param object $response + * @param AccessToken $token + * @return mixed + */ + abstract public function userDetails($response, AccessToken $token); + + public function getScopes() + { + return $this->scopes; + } + + public function setScopes(array $scopes) + { + $this->scopes = $scopes; + } + + public function getAuthorizationUrl($options = []) + { + $this->state = isset($options['state']) ? $options['state'] : md5(uniqid(rand(), true)); + + $params = [ + 'client_id' => $this->clientId, + 'redirect_uri' => $this->redirectUri, + 'state' => $this->state, + 'scope' => is_array($this->scopes) ? implode($this->scopeSeparator, $this->scopes) : $this->scopes, + 'response_type' => isset($options['response_type']) ? $options['response_type'] : 'code', + 'approval_prompt' => isset($options['approval_prompt']) ? $options['approval_prompt'] : 'auto', + ]; + + return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&'); + } + + // @codeCoverageIgnoreStart + public function authorize($options = []) + { + $url = $this->getAuthorizationUrl($options); + if ($this->redirectHandler) { + $handler = $this->redirectHandler; + return $handler($url); + } + // @codeCoverageIgnoreStart + header('Location: ' . $url); + exit; + // @codeCoverageIgnoreEnd + } + + public function getAccessToken($grant = 'authorization_code', $params = []) + { + if (is_string($grant)) { + // PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode' + $className = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $grant))); + $grant = 'League\\OAuth2\\Client\\Grant\\'.$className; + if (! class_exists($grant)) { + throw new \InvalidArgumentException('Unknown grant "'.$grant.'"'); + } + $grant = new $grant(); + } elseif (! $grant instanceof GrantInterface) { + $message = get_class($grant).' is not an instance of League\OAuth2\Client\Grant\GrantInterface'; + throw new \InvalidArgumentException($message); + } + + $defaultParams = [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + 'redirect_uri' => $this->redirectUri, + 'grant_type' => $grant, + ]; + + $requestParams = $grant->prepRequestParams($defaultParams, $params); + + try { + switch (strtoupper($this->method)) { + case 'GET': + // @codeCoverageIgnoreStart + // No providers included with this library use get but 3rd parties may + $client = $this->getHttpClient(); + $client->setBaseUrl($this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&')); + $request = $client->get(null, $this->getHeaders(), $requestParams)->send(); + $response = $request->getBody(); + break; + // @codeCoverageIgnoreEnd + case 'POST': + $client = $this->getHttpClient(); + $client->setBaseUrl($this->urlAccessToken()); + $request = $client->post(null, $this->getHeaders(), $requestParams)->send(); + $response = $request->getBody(); + break; + // @codeCoverageIgnoreStart + default: + throw new \InvalidArgumentException('Neither GET nor POST is specified for request'); + // @codeCoverageIgnoreEnd + } + } catch (BadResponseException $e) { + // @codeCoverageIgnoreStart + $response = $e->getResponse()->getBody(); + // @codeCoverageIgnoreEnd + } + + $result = $this->prepareResponse($response); + + if (isset($result['error']) && ! empty($result['error'])) { + // @codeCoverageIgnoreStart + throw new IDPException($result); + // @codeCoverageIgnoreEnd + } + + $result = $this->prepareAccessTokenResult($result); + + return $grant->handleResponse($result); + } + + /** + * Prepare the response, parsing according to configuration and returning + * the response as an array. + * + * @param string $response + * @return array + */ + protected function prepareResponse($response) + { + $result = []; + + switch ($this->responseType) { + case 'json': + $json = json_decode($response, true); + + if (JSON_ERROR_NONE === json_last_error()) { + $result = $json; + } + + break; + case 'string': + parse_str($response, $result); + break; + } + + return $result; + } + + /** + * Prepare the access token response for the grant. Custom mapping of + * expirations, etc should be done here. + * + * @param array $result + * @return array + */ + protected function prepareAccessTokenResult(array $result) + { + $this->setResultUid($result); + return $result; + } + + /** + * Sets any result keys we've received matching our provider-defined uidKey to the key "uid". + * + * @param array $result + */ + protected function setResultUid(array &$result) + { + // If we're operating with the default uidKey there's nothing to do. + if ($this->uidKey === "uid") { + return; + } + + if (isset($result[$this->uidKey])) { + // The AccessToken expects a "uid" to have the key "uid". + $result['uid'] = $result[$this->uidKey]; + } + } + + public function getUserDetails(AccessToken $token) + { + $response = $this->fetchUserDetails($token); + + return $this->userDetails(json_decode($response), $token); + } + + public function getUserUid(AccessToken $token) + { + $response = $this->fetchUserDetails($token, true); + + return $this->userUid(json_decode($response), $token); + } + + public function getUserEmail(AccessToken $token) + { + $response = $this->fetchUserDetails($token, true); + + return $this->userEmail(json_decode($response), $token); + } + + public function getUserScreenName(AccessToken $token) + { + $response = $this->fetchUserDetails($token, true); + + return $this->userScreenName(json_decode($response), $token); + } + + public function userUid($response, AccessToken $token) + { + return isset($response->id) && $response->id ? $response->id : null; + } + + public function userEmail($response, AccessToken $token) + { + return isset($response->email) && $response->email ? $response->email : null; + } + + public function userScreenName($response, AccessToken $token) + { + return isset($response->name) && $response->name ? $response->name : null; + } + + /** + * Build HTTP the HTTP query, handling PHP version control options + * + * @param array $params + * @param integer $numeric_prefix + * @param string $arg_separator + * @param null|integer $enc_type + * + * @return string + * @codeCoverageIgnoreStart + */ + protected function httpBuildQuery($params, $numeric_prefix = 0, $arg_separator = '&', $enc_type = null) + { + if (version_compare(PHP_VERSION, '5.4.0', '>=') && !defined('HHVM_VERSION')) { + if ($enc_type === null) { + $enc_type = $this->httpBuildEncType; + } + $url = http_build_query($params, $numeric_prefix, $arg_separator, $enc_type); + } else { + $url = http_build_query($params, $numeric_prefix, $arg_separator); + } + + return $url; + } + + protected function fetchUserDetails(AccessToken $token) + { + $url = $this->urlUserDetails($token); + + $headers = $this->getHeaders($token); + + return $this->fetchProviderData($url, $headers); + } + + protected function fetchProviderData($url, array $headers = []) + { + try { + $client = $this->getHttpClient(); + $client->setBaseUrl($url); + + if ($headers) { + $client->setDefaultOption('headers', $headers); + } + + $request = $client->get()->send(); + $response = $request->getBody(); + } catch (BadResponseException $e) { + // @codeCoverageIgnoreStart + $response = $e->getResponse()->getBody(); + $result = $this->prepareResponse($response); + throw new IDPException($result); + // @codeCoverageIgnoreEnd + } + + return $response; + } + + protected function getAuthorizationHeaders($token) + { + $headers = []; + if ($this->authorizationHeader) { + $headers['Authorization'] = $this->authorizationHeader . ' ' . $token; + } + return $headers; + } + + public function getHeaders($token = null) + { + $headers = $this->headers; + if ($token) { + $headers = array_merge($headers, $this->getAuthorizationHeaders($token)); + } + return $headers; + } + + public function setRedirectHandler(Closure $handler) + { + $this->redirectHandler = $handler; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Eventbrite.php b/vendor/league/oauth2-client/src/Provider/Eventbrite.php new file mode 100644 index 0000000..116051f --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Eventbrite.php @@ -0,0 +1,51 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; + +class Eventbrite extends AbstractProvider +{ + public $authorizationHeader = 'Bearer'; + + public function urlAuthorize() + { + return 'https://www.eventbrite.com/oauth/authorize'; + } + + public function urlAccessToken() + { + return 'https://www.eventbrite.com/oauth/token'; + } + + public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) + { + return 'https://www.eventbrite.com/json/user_get'; + } + + public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) + { + $user = new User(); + $user->exchangeArray([ + 'uid' => $response->user->user_id, + 'email' => $response->user->email, + ]); + + return $user; + } + + public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->user->user_id; + } + + public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return isset($response->user->email) && $response->user->email ? $response->user->email : null; + } + + public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->user->user_id; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Facebook.php b/vendor/league/oauth2-client/src/Provider/Facebook.php new file mode 100644 index 0000000..9155836 --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Facebook.php @@ -0,0 +1,103 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; + +class Facebook extends AbstractProvider +{ + /** + * @const string The fallback Graph API version to use for requests. + */ + const DEFAULT_GRAPH_VERSION = 'v2.2'; + + /** + * @var string The Graph API version to use for requests. + */ + protected $graphApiVersion; + + public $scopes = ['public_profile', 'email']; + + public $responseType = 'string'; + + public function __construct($options) + { + parent::__construct($options); + $this->graphApiVersion = (isset($options['graphApiVersion'])) + ? $options['graphApiVersion'] + : static::DEFAULT_GRAPH_VERSION; + } + + public function urlAuthorize() + { + return 'https://www.facebook.com/'.$this->graphApiVersion.'/dialog/oauth'; + } + + public function urlAccessToken() + { + return 'https://graph.facebook.com/'.$this->graphApiVersion.'/oauth/access_token'; + } + + public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) + { + $fields = implode(',', [ + 'id', + 'name', + 'first_name', + 'last_name', + 'email', + 'hometown', + 'bio', + 'picture.type(large){url}', + 'gender', + 'locale', + 'link', + ]); + + return 'https://graph.facebook.com/'.$this->graphApiVersion.'/me?fields='.$fields.'&access_token='.$token; + } + + public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) + { + $user = new User(); + + $email = (isset($response->email)) ? $response->email : null; + // The "hometown" field will only be returned if you ask for the `user_hometown` permission. + $location = (isset($response->hometown->name)) ? $response->hometown->name : null; + $description = (isset($response->bio)) ? $response->bio : null; + $imageUrl = (isset($response->picture->data->url)) ? $response->picture->data->url : null; + $gender = (isset($response->gender)) ? $response->gender : null; + $locale = (isset($response->locale)) ? $response->locale : null; + + $user->exchangeArray([ + 'uid' => $response->id, + 'name' => $response->name, + 'firstname' => $response->first_name, + 'lastname' => $response->last_name, + 'email' => $email, + 'location' => $location, + 'description' => $description, + 'imageurl' => $imageUrl, + 'gender' => $gender, + 'locale' => $locale, + 'urls' => [ 'Facebook' => $response->link ], + ]); + + return $user; + } + + public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->id; + } + + public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return isset($response->email) && $response->email ? $response->email : null; + } + + public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return [$response->first_name, $response->last_name]; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Github.php b/vendor/league/oauth2-client/src/Provider/Github.php new file mode 100644 index 0000000..8182a4e --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Github.php @@ -0,0 +1,99 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; +use League\OAuth2\Client\Token\AccessToken; + +class Github extends AbstractProvider +{ + public $responseType = 'string'; + + public $authorizationHeader = 'token'; + + public $domain = 'https://github.com'; + + public $apiDomain = 'https://api.github.com'; + + public function urlAuthorize() + { + return $this->domain.'/login/oauth/authorize'; + } + + public function urlAccessToken() + { + return $this->domain.'/login/oauth/access_token'; + } + + public function urlUserDetails(AccessToken $token) + { + if ($this->domain === 'https://github.com') { + return $this->apiDomain.'/user'; + } + return $this->domain.'/api/v3/user'; + } + + public function urlUserEmails(AccessToken $token) + { + if ($this->domain === 'https://github.com') { + return $this->apiDomain.'/user/emails'; + } + return $this->domain.'/api/v3/user/emails'; + } + + public function userDetails($response, AccessToken $token) + { + $user = new User(); + + $name = (isset($response->name)) ? $response->name : null; + $email = (isset($response->email)) ? $response->email : null; + + $user->exchangeArray([ + 'uid' => $response->id, + 'nickname' => $response->login, + 'name' => $name, + 'email' => $email, + 'urls' => [ + 'GitHub' => $this->domain.'/'.$response->login, + ], + ]); + + return $user; + } + + public function userUid($response, AccessToken $token) + { + return $response->id; + } + + public function getUserEmails(AccessToken $token) + { + $response = $this->fetchUserEmails($token); + + return $this->userEmails(json_decode($response), $token); + } + + public function userEmail($response, AccessToken $token) + { + return isset($response->email) && $response->email ? $response->email : null; + } + + public function userEmails($response, AccessToken $token) + { + return $response; + } + + public function userScreenName($response, AccessToken $token) + { + return $response->name; + } + + protected function fetchUserEmails(AccessToken $token) + { + $url = $this->urlUserEmails($token); + + $headers = $this->getHeaders($token); + + return $this->fetchProviderData($url, $headers); + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Google.php b/vendor/league/oauth2-client/src/Provider/Google.php new file mode 100644 index 0000000..87393ee --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Google.php @@ -0,0 +1,124 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; + +class Google extends AbstractProvider +{ + public $scopeSeparator = ' '; + + public $scopes = [ + 'profile', + 'email', + ]; + + public $authorizationHeader = 'OAuth'; + + /** + * @var string If set, this will be sent to google as the "hd" parameter. + * @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param + */ + public $hostedDomain = ''; + + public function setHostedDomain($hd) + { + $this->hostedDomain = $hd; + } + + public function getHostedDomain() + { + return $this->hostedDomain; + } + + /** + * @var string If set, this will be sent to google as the "access_type" parameter. + * @link https://developers.google.com/accounts/docs/OAuth2WebServer#offline + */ + public $accessType = ''; + + public function setAccessType($accessType) + { + $this->accessType = $accessType; + } + + public function getAccessType() + { + return $this->accessType; + } + + public function urlAuthorize() + { + return 'https://accounts.google.com/o/oauth2/auth'; + } + + public function urlAccessToken() + { + return 'https://accounts.google.com/o/oauth2/token'; + } + + public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) + { + return + 'https://www.googleapis.com/plus/v1/people/me?'. + 'fields=id%2Cname(familyName%2CgivenName)%2CdisplayName%2C'. + 'emails%2Fvalue%2Cimage%2Furl&alt=json'; + } + + public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) + { + $response = (array) $response; + + $user = new User(); + + $imageUrl = (isset($response['image']) && + $response['image']->url) ? $response['image']->url : null; + $email = + (isset($response['emails']) && + count($response['emails']) && + $response['emails'][0]->value)? $response['emails'][0]->value : null; + + $user->exchangeArray([ + 'uid' => $response['id'], + 'name' => $response['displayName'], + 'firstname' => $response['name']->givenName, + 'lastName' => $response['name']->familyName, + 'email' => $email, + 'imageUrl' => $imageUrl, + ]); + + return $user; + } + + public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->id; + } + + public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return ($response->emails && + count($response->emails) && + $response->emails[0]->value) ? $response->emails[0]->value : null; + } + + public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return [$response->name->givenName, $response->name->familyName]; + } + + public function getAuthorizationUrl($options = array()) + { + $url = parent::getAuthorizationUrl($options); + + if (!empty($this->hostedDomain)) { + $url .= '&' . $this->httpBuildQuery(['hd' => $this->hostedDomain]); + } + + if (!empty($this->accessType)) { + $url .= '&' . $this->httpBuildQuery(['access_type'=> $this->accessType]); + } + + return $url; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Instagram.php b/vendor/league/oauth2-client/src/Provider/Instagram.php new file mode 100644 index 0000000..0377c8a --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Instagram.php @@ -0,0 +1,59 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; + +class Instagram extends AbstractProvider +{ + public $scopeSeparator = ' '; + public $scopes = ['basic']; + public $responseType = 'json'; + + public function urlAuthorize() + { + return 'https://api.instagram.com/oauth/authorize'; + } + + public function urlAccessToken() + { + return 'https://api.instagram.com/oauth/access_token'; + } + + public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) + { + return 'https://api.instagram.com/v1/users/self?access_token='.$token; + } + + public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) + { + $user = new User(); + + $description = (isset($response->data->bio)) ? $response->data->bio : null; + + $user->exchangeArray([ + 'uid' => $response->data->id, + 'nickname' => $response->data->username, + 'name' => $response->data->full_name, + 'description' => $description, + 'imageUrl' => $response->data->profile_picture, + ]); + + return $user; + } + + public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->data->id; + } + + public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return; + } + + public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->data->full_name; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/LinkedIn.php b/vendor/league/oauth2-client/src/Provider/LinkedIn.php new file mode 100644 index 0000000..c790ddf --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/LinkedIn.php @@ -0,0 +1,76 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; +use League\OAuth2\Client\Token\AccessToken; + +class LinkedIn extends AbstractProvider +{ + public $scopes = []; + public $scopeSeparator = ' '; + public $responseType = 'json'; + public $authorizationHeader = 'Bearer'; + public $fields = [ + 'id', 'email-address', 'first-name', 'last-name', 'headline', + 'location', 'industry', 'picture-url', 'public-profile-url', + ]; + + public function urlAuthorize() + { + return 'https://www.linkedin.com/uas/oauth2/authorization'; + } + + public function urlAccessToken() + { + return 'https://www.linkedin.com/uas/oauth2/accessToken'; + } + + public function urlUserDetails(AccessToken $token) + { + $fields = implode(',', $this->fields); + return 'https://api.linkedin.com/v1/people/~:(' . $fields . ')?format=json'; + } + + public function userDetails($response, AccessToken $token) + { + $user = new User(); + + $email = (isset($response->emailAddress)) ? $response->emailAddress : null; + $location = (isset($response->location->name)) ? $response->location->name : null; + $description = (isset($response->headline)) ? $response->headline : null; + $pictureUrl = (isset($response->pictureUrl)) ? $response->pictureUrl : null; + $publicProfileUrl = (isset($response->publicProfileUrl)) ? $response->publicProfileUrl : null; + + $user->exchangeArray([ + 'uid' => $response->id, + 'name' => $response->firstName.' '.$response->lastName, + 'firstname' => $response->firstName, + 'lastname' => $response->lastName, + 'email' => $email, + 'location' => $location, + 'description' => $description, + 'imageurl' => $pictureUrl, + 'urls' => $publicProfileUrl, + ]); + + return $user; + } + + public function userUid($response, AccessToken $token) + { + return $response->id; + } + + public function userEmail($response, AccessToken $token) + { + return isset($response->emailAddress) && $response->emailAddress + ? $response->emailAddress + : null; + } + + public function userScreenName($response, AccessToken $token) + { + return [$response->firstName, $response->lastName]; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/Microsoft.php b/vendor/league/oauth2-client/src/Provider/Microsoft.php new file mode 100644 index 0000000..d0ed12e --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Microsoft.php @@ -0,0 +1,69 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; +use League\OAuth2\Client\Token\AccessToken; + +class Microsoft extends AbstractProvider +{ + public $scopes = ['wl.basic', 'wl.emails']; + public $responseType = 'json'; + + public function urlAuthorize() + { + return 'https://login.live.com/oauth20_authorize.srf'; + } + + public function urlAccessToken() + { + return 'https://login.live.com/oauth20_token.srf'; + } + + public function urlUserDetails(AccessToken $token) + { + return 'https://apis.live.net/v5.0/me?access_token='.$token; + } + + public function userDetails($response, AccessToken $token) + { + $client = $this->getHttpClient(); + $client->setBaseUrl('https://apis.live.net/v5.0/'.$response->id.'/picture'); + $request = $client->get()->send(); + $info = $request->getInfo(); + $imageUrl = $info['url']; + + $user = new User(); + + $email = (isset($response->emails->preferred)) ? $response->emails->preferred : null; + + $user->exchangeArray([ + 'uid' => $response->id, + 'name' => $response->name, + 'firstname' => $response->first_name, + 'lastname' => $response->last_name, + 'email' => $email, + 'imageurl' => $imageUrl, + 'urls' => $response->link.'/cid-'.$response->id, + ]); + + return $user; + } + + public function userUid($response, AccessToken $token) + { + return $response->id; + } + + public function userEmail($response, AccessToken $token) + { + return isset($response->emails->preferred) && $response->emails->preferred + ? $response->emails->preferred + : null; + } + + public function userScreenName($response, AccessToken $token) + { + return [$response->first_name, $response->last_name]; + } +} diff --git a/vendor/league/oauth2-client/src/Provider/ProviderInterface.php b/vendor/league/oauth2-client/src/Provider/ProviderInterface.php new file mode 100644 index 0000000..efe6087 --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/ProviderInterface.php @@ -0,0 +1,36 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Token\AccessToken as AccessToken; + +interface ProviderInterface +{ + public function urlAuthorize(); + + public function urlAccessToken(); + + public function urlUserDetails(AccessToken $token); + + public function userDetails($response, AccessToken $token); + + public function getScopes(); + + public function setScopes(array $scopes); + + public function getAuthorizationUrl($options = []); + + public function authorize($options = []); + + public function getAccessToken($grant = 'authorization_code', $params = []); + + public function getHeaders($token = null); + + public function getUserDetails(AccessToken $token); + + public function getUserUid(AccessToken $token); + + public function getUserEmail(AccessToken $token); + + public function getUserScreenName(AccessToken $token); +} diff --git a/vendor/league/oauth2-client/src/Provider/Vkontakte.php b/vendor/league/oauth2-client/src/Provider/Vkontakte.php new file mode 100644 index 0000000..da44ae2 --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Vkontakte.php @@ -0,0 +1,99 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; +use League\OAuth2\Client\Token\AccessToken; + +class Vkontakte extends AbstractProvider +{ + public $uidKey = 'user_id'; + + public function urlAuthorize() + { + return 'https://oauth.vk.com/authorize'; + } + + public function urlAccessToken() + { + return 'https://oauth.vk.com/access_token'; + } + + public function urlUserDetails(AccessToken $token) + { + $fields = ['nickname', + 'screen_name', + 'sex', + 'bdate', + 'city', + 'country', + 'timezone', + 'photo_50', + 'photo_100', + 'photo_200_orig', + 'has_mobile', + 'contacts', + 'education', + 'online', + 'counters', + 'relation', + 'last_seen', + 'status', + 'can_write_private_message', + 'can_see_all_posts', + 'can_see_audio', + 'can_post', + 'universities', + 'schools', + 'verified', ]; + + return "https://api.vk.com/method/users.get?user_id={$token->uid}&fields=" + .implode(",", $fields)."&access_token={$token}"; + } + + public function userDetails($response, AccessToken $token) + { + $response = $response->response[0]; + + $user = new User(); + + $email = (isset($response->email)) ? $response->email : null; + $location = (isset($response->country)) ? $response->country : null; + $description = (isset($response->status)) ? $response->status : null; + + $user->exchangeArray([ + 'uid' => $response->uid, + 'nickname' => $response->nickname, + 'name' => $response->screen_name, + 'firstname' => $response->first_name, + 'lastname' => $response->last_name, + 'email' => $email, + 'location' => $location, + 'description' => $description, + 'imageUrl' => $response->photo_200_orig, + ]); + + return $user; + } + + public function userUid($response, AccessToken $token) + { + $response = $response->response[0]; + + return $response->uid; + } + + public function userEmail($response, AccessToken $token) + { + $response = $response->response[0]; + + return isset($response->email) && $response->email ? $response->email : null; + } + + public function userScreenName($response, AccessToken $token) + { + $response = $response->response[0]; + + return [$response->first_name, $response->last_name]; + } +} diff --git a/vendor/league/oauth2-client/src/Token/AccessToken.php b/vendor/league/oauth2-client/src/Token/AccessToken.php new file mode 100755 index 0000000..bcfbfb1 --- /dev/null +++ b/vendor/league/oauth2-client/src/Token/AccessToken.php @@ -0,0 +1,77 @@ +<?php + +namespace League\OAuth2\Client\Token; + +use InvalidArgumentException; + +class AccessToken +{ + /** + * @var string accessToken + */ + public $accessToken; + + /** + * @var int expires + */ + public $expires; + + /** + * @var string refreshToken + */ + public $refreshToken; + + /** + * @var string uid + */ + public $uid; + + /** + * Sets the token, expiry, etc values. + * + * @param array $options token options + * @return void + */ + public function __construct(array $options = null) + { + if (! isset($options['access_token'])) { + throw new \InvalidArgumentException( + 'Required option not passed: access_token'.PHP_EOL + .print_r($options, true) + ); + } + + $this->accessToken = $options['access_token']; + + if (!empty($options['uid'])) { + $this->uid = $options['uid']; + } + + if (!empty($options['refresh_token'])) { + $this->refreshToken = $options['refresh_token']; + } + + // We need to know when the token expires. Show preference to + // 'expires_in' since it is defined in RFC6749 Section 5.1. + // Defer to 'expires' if it is provided instead. + if (!empty($options['expires_in'])) { + $this->expires = time() + ((int) $options['expires_in']); + } elseif (!empty($options['expires'])) { + // Some providers supply the seconds until expiration rather than + // the exact timestamp. Take a best guess at which we received. + $expires = $options['expires']; + $expiresInFuture = $expires > time(); + $this->expires = $expiresInFuture ? $expires : time() + ((int) $expires); + } + } + + /** + * Returns the token key. + * + * @return string + */ + public function __toString() + { + return (string) $this->accessToken; + } +} |