-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ursuleacv/1.0-dev
Initial release
- Loading branch information
Showing
12 changed files
with
757 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/build | ||
/vendor | ||
composer.phar | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --no-interaction --prefer-source --dev | ||
- travis_retry phpenv rehash | ||
|
||
script: | ||
- ./vendor/bin/phpcs --standard=psr2 src/ | ||
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover | ||
|
||
after_script: | ||
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi | ||
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# CHANGELOG | ||
|
||
## 1.0.0 - March 14, 2016 | ||
|
||
- Updated `composer.json` | ||
- Getting AccountId | ||
- Getting Sale details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Contributing | ||
|
||
Contributions are **welcome**. | ||
|
||
We accept contributions via Pull Requests on [Github](https://github.com/ursuleacv/oauth2-lightspeed). | ||
|
||
|
||
## 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). | ||
|
||
- **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 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**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Valentin Ursuleac <[email protected]> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,112 @@ | ||
# oauth2-lightspeed | ||
# LightSpeed Provider for OAuth 2.0 Client | ||
|
||
This package provides LightSpeed OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/ursuleacv/oauth2-client). | ||
|
||
This package is compliant with [PSR-1][], [PSR-2][], [PSR-4][], and [PSR-7][]. 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 | ||
[PSR-7]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md | ||
|
||
|
||
## Requirements | ||
|
||
The following versions of PHP are supported. | ||
|
||
* PHP 5.5 | ||
* PHP 5.6 | ||
* PHP 7.0 | ||
* HHVM | ||
|
||
## Installation | ||
|
||
Add the following to your `composer.json` file. | ||
|
||
```json | ||
{ | ||
"require": { | ||
"ursuleacv/oauth2-lightspeed": "~1.0" | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
### Authorization Code Flow | ||
|
||
```php | ||
session_start(); | ||
|
||
$provider = new League\OAuth2\Client\Provider\Lightspeed([ | ||
'clientId' => LIGHTSPEED_CLIENT_ID, | ||
'clientSecret' => LIGHTSPEED_CLIENT_SECRET, | ||
'redirectUri' => LIGHTSPEED_REDIRECT_URI, | ||
'accountId' => LIGHTSPEED_ACCOUNT_ID, | ||
]); | ||
|
||
if (!isset($_GET['code'])) { | ||
|
||
// If we don't have an authorization code then get one | ||
$authUrl = $provider->getAuthorizationUrl([ | ||
'scope' => ['employee:all', '...', '...'], | ||
]); | ||
$_SESSION['oauth2state'] = $provider->getState(); | ||
|
||
echo '<a href="'.$authUrl.'">Log in with LightSpeed!</a>'; | ||
exit; | ||
|
||
// Check given state against previously stored one to mitigate CSRF attack | ||
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { | ||
|
||
unset($_SESSION['oauth2state']); | ||
echo 'Invalid state.'; | ||
exit; | ||
|
||
} | ||
|
||
// Try to get an access token (using the authorization code grant) | ||
$token = $provider->getAccessToken('authorization_code', [ | ||
'code' => $_GET['code'] | ||
]); | ||
|
||
try { | ||
|
||
// We got an access token, let's now get the Account ID and sale details | ||
$client = $ls->getAccountId($token); | ||
$sale = $ls->getSale($token, 1); | ||
|
||
echo '<pre>'; | ||
print_r($client); echo '<br>'; | ||
print_r($sale); echo '<br>'; | ||
echo '</pre>'; | ||
|
||
} catch (Exception $e) { | ||
exit($e->getMessage()); | ||
} | ||
|
||
echo '<pre>'; | ||
// Use this to interact with an API on the client behalf | ||
var_dump($token->getToken()); | ||
|
||
echo '</pre>'; | ||
``` | ||
|
||
## Testing | ||
|
||
``` bash | ||
$ ./vendor/bin/phpunit | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](https://github.com/ursuleacv/oauth2-lightspeed/blob/master/CONTRIBUTING.md) for details. | ||
|
||
|
||
## Credits | ||
|
||
- [Valentin Ursuleac](https://github.com/ursuleacv) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](https://github.com/ursuleacv/oauth2-lightspeed/blob/master/LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "ursuleacv/oauth2-lightspeed", | ||
"description": "LightSpeed OAuth 2.0 Client Provider for The PHP League OAuth2-Client", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"authors": [ | ||
{ | ||
"name": "Valentin Ursuleac", | ||
"email": "[email protected]", | ||
"homepage": "http://valnet.ca", | ||
"role": "Developer" | ||
} | ||
], | ||
"keywords": [ | ||
"oauth", | ||
"oauth2", | ||
"client", | ||
"authorization", | ||
"authentication", | ||
"LightSpeed" | ||
], | ||
"require": { | ||
"php": ">=5.5.0", | ||
"league/oauth2-client": "~1.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.0", | ||
"mockery/mockery": "~0.9", | ||
"squizlabs/php_codesniffer": "~2.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"League\\OAuth2\\Client\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"League\\OAuth2\\Client\\Test\\": "tests/src/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="display_errors" value="On" /> | ||
<ini name="display_startup_errors" value="On" /> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Grant; | ||
|
||
class LsExchangeToken extends AbstractGrant | ||
{ | ||
public function __toString() | ||
{ | ||
return 'ls_exchange_token'; | ||
} | ||
|
||
protected function getRequiredRequestParameters() | ||
{ | ||
return [ | ||
'ls_exchange_token', | ||
]; | ||
} | ||
|
||
protected function getName() | ||
{ | ||
return 'ls_exchange_token'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Provider\Exception; | ||
|
||
class LightspeedProviderException extends \Exception | ||
{ | ||
} |
Oops, something went wrong.