-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,058 additions
and
0 deletions.
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,6 @@ | ||
/build | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.idea |
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,35 @@ | ||
filter: | ||
excluded_paths: [test/*] | ||
checks: | ||
php: | ||
code_rating: true | ||
remove_extra_empty_lines: true | ||
remove_php_closing_tag: true | ||
remove_trailing_whitespace: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: true | ||
order_alphabetically: true | ||
fix_php_opening_tag: true | ||
fix_linefeed: true | ||
fix_line_ending: true | ||
fix_identation_4spaces: true | ||
fix_doc_comments: true | ||
tools: | ||
external_code_coverage: | ||
timeout: 600 | ||
runs: 2 | ||
php_analyzer: true | ||
php_code_coverage: false | ||
php_code_sniffer: | ||
config: | ||
standard: PSR2 | ||
filter: | ||
paths: ['src'] | ||
php_loc: | ||
enabled: true | ||
excluded_dirs: [vendor, test] | ||
php_cpd: | ||
enabled: true | ||
excluded_dirs: [vendor, test] |
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,5 @@ | ||
--- | ||
:major: 1 | ||
:minor: 0 | ||
:patch: 0 | ||
:special: '' |
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,27 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- hhvm | ||
|
||
matrix: | ||
include: | ||
- php: 5.6 | ||
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' | ||
|
||
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: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
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 @@ | ||
Contributing | ||
============ | ||
|
||
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions. |
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,26 @@ | ||
The MIT License | ||
|
||
Copyright 2009-2019 | ||
Cake Development Corporation | ||
1785 E. Sahara Avenue, Suite 490-423 | ||
Las Vegas, Nevada 89104 | ||
Phone: +1 702 425 5085 | ||
https://www.cakedc.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. |
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,130 @@ | ||
# Amazon Cognito Provider for OAuth 2.0 Client | ||
[![Latest Version](https://img.shields.io/github/release/cakedc/oauth2-cognito.svg?style=flat-square)](https://github.com/cakedc/oauth2-cognito/releases) | ||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) | ||
[![Build Status](https://img.shields.io/travis/cakedc/oauth2-cognito/master.svg?style=flat-square)](https://travis-ci.org/cakedc/oauth2-cognito) | ||
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/cakedc/oauth2-cognito.svg?style=flat-square)](https://scrutinizer-ci.com/g/cakedc/oauth2-cognito/code-structure) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/cakedc/oauth2-cognito.svg?style=flat-square)](https://scrutinizer-ci.com/g/cakedc/oauth2-cognito) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/cakedc/oauth2-cognito.svg?style=flat-square)](https://packagist.org/packages/cakedc/oauth2-cognito) | ||
|
||
This package provides Amazon Cognito OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client). | ||
|
||
## Installation | ||
|
||
To install, use composer: | ||
|
||
``` | ||
composer require cakedc/oauth2-cognito | ||
``` | ||
|
||
## Usage | ||
|
||
Usage is the same as The League's OAuth client, using `\CakeDC\OAuth2\Client\Provider\Cognito` as the provider. | ||
|
||
### Authorization Code Flow | ||
|
||
```php | ||
$provider = new CakeDC\OAuth2\Client\Provider\Cognito([ | ||
'clientId' => '{cognito-client-id}', | ||
'clientSecret' => '{cognito-client-secret}', | ||
'redirectUri' => 'https://example.com/callback-url', | ||
'cognitoDomain' => '{cognito-client-domain}', | ||
]); | ||
|
||
if (!isset($_GET['code'])) { | ||
|
||
// If we don't have an authorization code then get one | ||
$authUrl = $provider->getAuthorizationUrl(); | ||
$_SESSION['oauth2state'] = $provider->getState(); | ||
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 | ||
$user = $provider->getResourceOwner($token); | ||
|
||
// Use these details to create a new profile | ||
printf('Hello %s!', $user->getName()); | ||
|
||
} catch (Exception $e) { | ||
|
||
// Failed to get user details | ||
exit('Oh dear...'); | ||
} | ||
|
||
// Use this to interact with an API on the users behalf | ||
echo $token->getToken(); | ||
} | ||
``` | ||
|
||
### Managing Scopes | ||
|
||
When creating your Amazon Cognito authorization URL, you can specify the state and scopes your application may authorize. | ||
|
||
```php | ||
$options = [ | ||
'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE', | ||
'scope' => ['email','phone','profile'] | ||
]; | ||
|
||
$authorizationUrl = $provider->getAuthorizationUrl($options); | ||
``` | ||
If neither are defined, the provider will utilize internal defaults. | ||
|
||
At the time of authoring this documentation, the [following scopes are available](https://instagram.com/developer/authentication/#scope). | ||
|
||
- phone | ||
- profile | ||
- openid (required for phone, email or profile) | ||
- | ||
|
||
##Hosted domain | ||
|
||
Optionally, if you are using your own domain for you client, you can configure it instead of `cognitoDomain` option when the provider is initialized: | ||
|
||
```php | ||
$provider = new CakeDC\OAuth2\Client\Provider\Cognito([ | ||
'clientId' => '{cognito-client-id}', | ||
'clientSecret' => '{cognito-client-secret}', | ||
'redirectUri' => 'https://example.com/callback-url', | ||
'hostedDomain' => '{cognito-hosted-domain}', //Full domain without trailing slash | ||
]); | ||
|
||
``` | ||
|
||
## Testing | ||
|
||
``` bash | ||
$ ./vendor/bin/phpunit | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](https://github.com/cakedc/oauth2-cognito/blob/master/CONTRIBUTING.md) for details. | ||
|
||
|
||
## Credits | ||
|
||
- [Cake Development Corporation](https://github.com/cakedc) | ||
- [Alejandro Ibarra](https://github.com/ajibarra) | ||
- [All Contributors](https://github.com/cakedc/oauth2-cognito/contributors) | ||
|
||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](https://github.com/cakedc/oauth2-cognito/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,39 @@ | ||
{ | ||
"name": "cakedc/oauth2-cognito", | ||
"description": "Cognito OAuth 2.0 Client Provider for The PHP League OAuth2-Client", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "CakeDC", | ||
"email": "[email protected]", | ||
"homepage": "https://www.cakedc.com" | ||
} | ||
], | ||
"keywords": [ | ||
"oauth", | ||
"oauth2", | ||
"client", | ||
"authorization", | ||
"authentication", | ||
"cognito" | ||
], | ||
"require": { | ||
"php": "^5.6 || ^7.0", | ||
"league/oauth2-client": "^2.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8", | ||
"mockery/mockery": "~0.9", | ||
"squizlabs/php_codesniffer": "~2.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CakeDC\\OAuth2\\Client\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"CakeDC\\OAuth2\\Client\\Test\\": "tests/src/" | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?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" | ||
> | ||
<logging> | ||
<log type="coverage-html" | ||
target="./build/coverage/html" | ||
lowUpperBound="35" | ||
highLowerBound="70"/> | ||
<log type="coverage-clover" | ||
target="./build/coverage/log/coverage.xml"/> | ||
</logging> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./test/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./</directory> | ||
<exclude> | ||
<directory suffix=".php">./vendor</directory> | ||
<directory suffix=".php">./test</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.