Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dalpras-vimar committed Jan 31, 2019
0 parents commit 1ddc872
Show file tree
Hide file tree
Showing 18 changed files with 1,601 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build
/vendor
composer.phar
composer.lock
.DS_Store
35 changes: 35 additions & 0 deletions .scrutinizer.yml
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: 3
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]
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: php

sudo: false

php:
- 7.1
- 7.2
- 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
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Citrix GoToWebinar](https://github.com/dalpras/oauth2-gotowebinar).


## Running Tests

``` bash
./vendor/bin/phpunit
```


## Running PHP Code Sniffer

``` bash
./vendor/bin/phpcs src --standard=psr2 -sp
```

**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Stefano Dal Prà

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.
181 changes: 181 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Citrix GoToWebinar Provider for OAuth 2.0 Client

This package provides Citrix GoToWebinar OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

## Installation

To install, use composer:

```bash
composer require dalpras/oauth2-gotowebinar
```

## Usage

Usage is the same as The League's OAuth client, using `\DalPraS\OAuth2\Client\Provider\GotoWebinar` as the provider.

### Authorization Code Flow

```php

$development = true;
$provider = new \DalPraS\OAuth2\Client\Provider\GotoWebinar([
// The client ID assigned to you by the provider
'clientId' => 'your gotowebinar client id',
// The client ID assigned to you by the provider
'clientSecret' => 'your gotowebinar client password',
'redirectUri' => 'your redirect uri after authorization'
], [
// optional
'httpClient' => new \GuzzleHttp\Client([
// setup some options for using with localhost
'verify' => $development ? false : true,
// timeout connection
'timeout' => 60
])
]);

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->getNickname());

} catch (GotoWebinarProviderException $e) {
return $e->generateHttpResponse(new \Zend\Diactoros\Response());

} 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();
}
```

### Refreshing a token

```php
$provider = new \DalPraS\OAuth2\Client\Provider\GotoWebinar([
'clientId' => 'demoapp', // The client ID assigned to you by the provider
'clientSecret' => 'demopass', // The client password assigned to you by the provider
'redirectUri' => 'http://example.com/your-redirect-url/',
]);

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $existingAccessToken->getRefreshToken()
]);
// Purge old access token and store new access token to your data store.
}
```

### Using GotoWebinar WEB API

Interaction with the GoToWebinar API is very easy.

```php
$provider = new \DalPraS\OAuth2\Client\Provider\GotoWebinar([
'clientId' => 'demoapp', // The client ID assigned to you by the provider
'clientSecret' => 'demopass', // The client password assigned to you by the provider
'redirectUri' => 'http://example.com/your-redirect-url/',
]);

$accessToken = getAccessTokenFromYourDataStore();

$resWebinar = new \DalPraS\OAuth2\Client\Resources\Webinar($provider, $accessToken);
try {
$data = $resWebinar->getWebinars();

// or
$data = $resWebinar->getPast(new \DateTime('-1 year'));

// or
$data = $resWebinar->getWebinar('webinarKey');

// or
$data = $resWebinar->deleteWebinar('webinarKey');

// or
$data = $resWebinar->getUpcoming();

// or
// helper for changing timezone to utc
$dateUtcHelper = new \DalPraS\OAuth2\Client\Helper\DateUtcHelper();
$data = $resWebinar->createWebinar([
"subject" => "My first webinar",
"times" => [[
"startTime" => $dateUtcHelper->date2utc(new \DateTime('+1 day')),
"endTime" => $dateUtcHelper->date2utc(new \DateTime('+2 days')),
]],
]);

// or
$data = $resRegistrant->getRegistrants('webinarKey');

// or
$data = $resRegistrant->getRegistrant('webinarKey', 'registrantKey');

// or
$data = $resRegistrant->getRegistrantByEmail('webinarKey', '[email protected]');

// or
$data = $resRegistrant->createRegistrant('webinarKey', [
'firstName' => 'Ronnie',
'lastName' => 'Test',
'email' => '[email protected]'
]);

// or
$data = $resRegistrant->deleteRegistrant('webinarKey', 'registrantKey');

return json_encode($data);

} catch (GotoWebinarProviderException $e) {
// return a psr7 response message (using for example zend\diactoros)
return $e->generateHttpResponse(new \Zend\Diactoros\Response());

} catch (\Exception $e) {
die($e->getMessage());

}
```

## Testing

```bash
./vendor/bin/phpunit
```

## License

The MIT License (MIT). Please see [License File](https://github.com/dalpras/oauth2-gotowebinar/blob/master/LICENSE) for more information.
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name" : "dalpras/oauth2-gotowebinar",
"description" : "Citrix GoToWebinar OAuth 2.0 Client Provider for the PHP League's OAuth 2.0 Client",
"license" : "MIT",
"authors" : [{
"name" : "Stefano Dal Prà",
"email" : "[email protected]",
"homepage" : "https://github.com/dalpras"
}
],
"keywords" : [
"oauth",
"oauth2",
"client",
"authorization",
"authorisation",
"citrix",
"gotowebinar",
"logmeinic"
],
"require" : {
"league/oauth2-client" : "^2.0"
},
"require-dev" : {
"phpunit/phpunit" : "~4.0",
"mockery/mockery" : "~0.9",
"squizlabs/php_codesniffer" : "~2.0"
},
"autoload" : {
"psr-4" : {
"DalPraS\\OAuth2\\Client\\" : "src/"
}
},
"autoload-dev" : {
"psr-4" : {
"DalPraS\\OAuth2\\Client\\Test\\" : "test/src/"
}
},
"extra" : {
"branch-alias" : {
"dev-master" : "1.0.x-dev"
}
}
}
37 changes: 37 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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"
>
<logging>
<log type="coverage-html"
target="./build/coverage/html"
charset="UTF-8"
highlight="false"
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>
Loading

0 comments on commit 1ddc872

Please sign in to comment.