Skip to content

Commit

Permalink
Update library for Public Media SSO OIDC public client
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Nov 15, 2024
1 parent 12281c8 commit 56c6e4e
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 180 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ composer.lock
.DS_Store

# PHPUnit
.phpunit.result.cache
.phpunit.result.cache
.phpunit.cache
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ We accept contributions via Pull Requests on [Github](https://github.com/OpenPub
## Running Tests

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


## Running PHP Code Sniffer

``` bash
$ ./vendor/bin/phpcs src --standard=psr2 -sp
./vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility
./vendor/bin/phpcs
```

**Happy coding**!
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# PBS Provider for OAuth 2.0 Client
# PBS Provider for Public Media SSO Client

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

## Legacy PBS OAuth 2.0

For legacy PBS OAuth 2.0 support, use a 1.x versions of this library.

## Installation

To install, use composer:

```
```shell
composer require openpublicmedia/oauth2-pbs
```

Expand All @@ -19,7 +23,7 @@ Usage is the same as The League's OAuth client, using `OpenPublicMedia\OAuth2\Cl
```php
$provider = new OpenPublicMedia\OAuth2\Client\Provider\Pbs([
'clientId' => '{pbs-client-id}',
'clientSecret' => '{pbs-client-secret}',
'customerId' => '{pbs-customer-id}',
'redirectUri' => 'https://example.com/callback-url',
]);

Expand All @@ -28,6 +32,10 @@ if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();

// Add PKCE code to session.
$_SESSION['oauth2pkceCode'] = $provider->getPkceCode();

header('Location: '.$authUrl);
exit;

Expand All @@ -39,6 +47,9 @@ if (!isset($_GET['code'])) {

} else {

// Restore the PKCE code stored in the session.
$provider->setPkceCode($_SESSION['oauth2pkceCode']);

// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
Expand All @@ -64,23 +75,17 @@ if (!isset($_GET['code'])) {
}
```

## Testing

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

## Contributing

Please see [CONTRIBUTING](https://github.com/cascade-public-media/oauth2-pbs/blob/master/CONTRIBUTING.md) for details.
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.


## Credits

- [Christopher C. Wells](https://chrxs.net)
- [All Contributors](https://github.com/cascade-public-media/oauth2-pbs/contributors)
- [Christopher C. Wells](https://www.chris-wells.net)
- [All Contributors](https://github.com/openpublicmedia/oauth2-pbs/graphs/contributors)


## License

The MIT License (MIT). Please see [License File](https://github.com/cascade-public-media/oauth2-pbs/blob/master/LICENSE) for more information.
The MIT License (MIT). Please see [License File](LICENSE) for more information.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"league/oauth2-client": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^10.0",
"mockery/mockery": "^1.0",
"squizlabs/php_codesniffer": "^3.0",
"phpcompatibility/php-compatibility": "^9.3"
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
<file>src/</file>
<file>test/</file>

<config name="testVersion" value="7.4-"/>
<config name="testVersion" value="8.0-"/>
</ruleset>
54 changes: 22 additions & 32 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
<?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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="./build/coverage/log/coverage.xml"/>
<html outputDirectory="./build/coverage/html" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<logging/>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./test</directory>
</exclude>
</source>
</phpunit>
12 changes: 7 additions & 5 deletions src/Provider/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
class Apple extends Pbs
{
/**
* Get authorization url to begin OAuth flow.
*
* @return string
* {@inheritDoc}
*/
public function getBaseAuthorizationUrl()
protected function getAuthorizationParameters(array $options)
{
return $this->domain . '/oauth2/social/login/apple';
return parent::getAuthorizationParameters($options + [
'backend' => 'apple',
'prompt' => 'login',
'show_social_signin' => 'on',
]);
}
}
12 changes: 7 additions & 5 deletions src/Provider/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
class Facebook extends Pbs
{
/**
* Get authorization url to begin OAuth flow.
*
* @return string
* {@inheritDoc}
*/
public function getBaseAuthorizationUrl()
protected function getAuthorizationParameters(array $options)
{
return $this->domain . '/oauth2/social/login/facebook';
return parent::getAuthorizationParameters($options + [
'backend' => 'facebook',
'prompt' => 'login',
'show_social_signin' => 'on',
]);
}
}
12 changes: 7 additions & 5 deletions src/Provider/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
class Google extends Pbs
{
/**
* Get authorization url to begin OAuth flow.
*
* @return string
* {@inheritDoc}
*/
public function getBaseAuthorizationUrl()
protected function getAuthorizationParameters(array $options)
{
return $this->domain . '/oauth2/social/login/google-oauth2';
return parent::getAuthorizationParameters($options + [
'backend' => 'google-oauth2',
'prompt' => 'login',
'show_social_signin' => 'on',
]);
}
}
Loading

0 comments on commit 56c6e4e

Please sign in to comment.