Skip to content
Snippets Groups Projects
Commit c2134857 authored by WitteStier's avatar WitteStier
Browse files

Add readme, contributing guide, changelog and license file

parent 391a582a
No related branches found
No related tags found
No related merge requests found
# Changelog
All Notable changes to `oauth2-meetup` will be documented in this file
## 0.1.0 - 2018-02-12
### Added
- Initial release!
### Deprecated
- Nothing
### Fixed
- Nothing
### Removed
- Nothing
### Security
- Nothing
# Contributing
Contributions are **welcome** and will be fully **credited**.
We accept contributions via Pull Requests on [GitLab](https://gitlab.com/WitteStier/oauth2-meetup).
## 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**!
LICENSE 0 → 100644
MIT License
Copyright (c) 2018 WitteStier
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.
README.md 0 → 100644
Meetup Provider for OAuth 2.0 Client
====================================
This package provides Meetup.com OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).
## Requirements
The following versions of PHP are supported.
* PHP 7.0
* PHP 7.1
* PHP 7.2
## Installation
To install, use composer:
``` bash
composer require wittestier/oauth2-meetup
```
## Usage
### Authorization Code Flow
``` php
$provider = new \WitteStier\OAuth2\Client\Provider\Meetup([
'clientId' => '{meetup-consumer-key}',
'clientSecret' => '{meetup-consumer-secret}',
'redirectUri' => '{meetup-consumer-redirect-uri}',
]);
// If we don't have an authorization code then get one.
if (isset($_GET['code']) === false) {
// Fetch the authorization URL from the provider; this returns the urlAuthorize option and generates and applies
// any necessary parameters (e.g. state).
$authorizationUrl = $provider->getAuthorizationUrl();
// Get the state generated for you and store it to the session.
$_SESSION['oauth2state'] = $provider->getState();
// Redirect the user to the authorization URL.
header('Location: ' . $authorizationUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack.
} elseif (empty($_GET['state']) === true || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
try {
// Try to get an access token using the authorization code grant.
$grant = new League\OAuth2\Client\Grant\AuthorizationCode();
$accessToken = $provider->getAccessToken($grant, [
'code' => $_GET['code']
]);
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token or user details.
exit($e->getMessage());
}
// We have an access token, which we may use in authenticated requests against the service provider's API.
echo $accessToken->getToken() . "\n";
echo $accessToken->getRefreshToken() . "\n";
echo $accessToken->getExpires() . "\n";
echo ($accessToken->hasExpired() ? 'expired' : 'not expired') . "\n";
try {
// Using the access token, we may look up details about the resource owner.
$resourceOwner = $provider->getResourceOwner($accessToken);
var_export($resourceOwner->toArray());
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token or user details.
exit($e->getMessage());
}
}
```
### Managing Scopes
When creating your Meetup authorization URL, you can specify the state and scopes your application may authorize.
``` php
$options = [
'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
'scope' => [ 'ageless', 'basic', 'event_management', 'group_edit', 'group_content_edit', 'group_join', 'messaging', 'profile_edit', 'reporting', 'rsvp' ],
];
$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://www.meetup.com/meetup_api/auth/#oauth2-scopes)
### Refreshing a Token
``` php
$provider = new \WitteStier\OAuth2\Client\Provider\Meetup([
'clientId' => '{meetup-consumer-key}',
'clientSecret' => '{meetup-consumer-secret}',
'redirectUri' => '{meetup-consumer-redirect-uri}',
]);
// Fetch your token from a datastore.
$token = fetchAccessToken();
$refreshToken = $token->getRefreshToken();
if ($token->hasExpired() === true) {
$grant = new League\OAuth2\Client\Grant\RefreshToken();
$newAccessToken = $provider->getAccessToken($grant, [
'refresh_token' => $token->getRefreshToken()
]);
// Purge old access token and store new access token to your data store.
}
```
## Testing
``` bash
$ ./vendor/bin/phpunit
# Or
$ composer test
```
``` bash
$ ./vendor/bin/phpcs src --standard=psr2 -sp
# Or
$ composer check
```
## Contributing
Please see [CONTRIBUTING](https://gitlab.com/WitteStier/oauth2-meetup/blob/master/CONTRIBUTING.md) for details.
## Credits
- [WitteStier](https://gitlab.com/WitteStier)
- [All Contributors](https://gitlab.com/WitteStier/oauth2-meetup/graphs/master)
## License
The MIT License (MIT). Please see [License File](https://gitlab.com/WitteStier/oauth2-meetup/blob/master/LICENSE) for more information.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment