Skip to content
  • Sponsor chillerlan/php-oauth

  • Notifications You must be signed in to change notification settings
  • Fork 0

Commit c880698

Browse files
committedMay 20, 2024·
📖
1 parent f8a7457 commit c880698

24 files changed

+77
-30
lines changed
 

‎README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ A transparent, framework-agnostic, easily extensible PHP [PSR-18](https://www.ph
4444
- [RFC-7009: Token Revocation](https://datatracker.ietf.org/doc/html/rfc7009)
4545
- [RFC-7636: PKCE](https://datatracker.ietf.org/doc/html/rfc7636) (Proof Key for Code Exchange)
4646
- [RFC-9126: PAR](https://datatracker.ietf.org/doc/html/rfc9126) (Pushed Authorization Requests)
47+
- ~~[RFC-9449: DPoP](https://datatracker.ietf.org/doc/html/rfc9449) (Demonstrating Proof of Possession)~~ ([planned](https://github.com/chillerlan/php-oauth/issues/3))
4748
- Proprietary, OAuth-like authorization flows (e.g. [Last.fm](https://www.last.fm/api/authentication))
4849
- Invalidation of access tokens (if supported by the provider)
4950
- Several built-in provider implementations ([see below](#implemented-providers))
@@ -67,6 +68,9 @@ A transparent, framework-agnostic, easily extensible PHP [PSR-18](https://www.ph
6768
- The user manual is at https://php-oauth.readthedocs.io/ ([sources](https://github.com/chillerlan/php-oauth/tree/main/docs))
6869
- An API documentation created with [phpDocumentor](https://www.phpdoc.org/) can be found at https://chillerlan.github.io/php-oauth/
6970
- The documentation for the `AccessToken`, `AuthenticatedUser` and `OAuthOptions` containers can be found here: [chillerlan/php-settings-container](https://github.com/chillerlan/php-settings-container#readme)
71+
- There is [the suite of get-token examples](https://php-oauth.readthedocs.io/en/main/Usage/Using-examples.html), which is mostly intended for development, and there are self-contained examples for a quickstart:
72+
- [OAuth1 example](https://github.com/chillerlan/php-oauth/tree/main/examples/example-oauth1.php)
73+
- [OAuth2 example](https://github.com/chillerlan/php-oauth/tree/main/examples/example-oauth2.php)
7074

7175

7276
## Installation with [composer](https://getcomposer.org)
@@ -95,16 +99,6 @@ composer require chillerlan/php-oauth
9599
Note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^1.0` - see [releases](https://github.com/chillerlan/php-oauth/releases) for valid versions.
96100

97101

98-
## Examples
99-
100-
There is [the suite of get-token examples](https://php-oauth.readthedocs.io/en/main/Usage/Using-examples.html),
101-
which is mostly intended for development, and there are self-contained examples for a quickstart:
102-
103-
- [OAuth1 example](https://github.com/chillerlan/php-oauth/tree/main/examples/example-oauth1.php)
104-
- [OAuth2 example](https://github.com/chillerlan/php-oauth/tree/main/examples/example-oauth2.php)
105-
106-
107-
108102
# Implemented Providers
109103

110104
<!-- TABLE-START -->

‎src/Storage/OAuthStorageInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
use Psr\Log\LoggerInterface;
1616

1717
/**
18-
* Specifies the methods required for an OAuth token storage adapter
18+
* Specifies the methods required for an OAuth storage adapter
1919
*
20-
* The token storage is intended to be invoked per-user,
21-
* for whom it can store tokens for any of the implemented providers.
20+
* The storage is intended to be invoked per-user, for whom it can
21+
* store tokens, state etc. for any of the implemented providers.
2222
*
2323
* The implementer must ensure that the same storage instance is not used for multiple users.
2424
*/

‎tests/Attributes/Provider.php

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* Supplies the provider class name
18+
*
19+
* example: `#[Provider(GitHub::class)]`
1820
*/
1921
#[Attribute(Attribute::TARGET_CLASS)]
2022
final class Provider{

‎tests/Core/AuthenticatedUserTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use PHPUnit\Framework\TestCase;
1717

1818
/**
19-
*
19+
* Tests the AuthenticatedUser class
2020
*/
2121
final class AuthenticatedUserTest extends TestCase{
2222

@@ -80,10 +80,10 @@ public static function displayNameProvider():array{
8080
}
8181

8282
#[DataProvider('displayNameProvider')]
83-
public function testSetDisplayName(string|null $displayName, string|null $expexted):void{
83+
public function testSetDisplayName(string|null $displayName, string|null $expected):void{
8484
$user = new AuthenticatedUser(['displayName' => $displayName]);
8585

86-
$this::assertSame($expexted, $user->displayName);
86+
$this::assertSame($expected, $user->displayName);
8787
}
8888

8989
}

‎tests/Core/OAuthOptionsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use PHPUnit\Framework\TestCase;
1717

1818
/**
19-
*
19+
* Tests the OAuthOptions class
2020
*/
2121
class OAuthOptionsTest extends TestCase{
2222

‎tests/Core/OAuthProviderFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use function realpath;
2424

2525
/**
26-
*
26+
* Tests the OAuthProviderFactory class
2727
*/
2828
class OAuthProviderFactoryTest extends TestCase{
2929
use HttpFactoryTrait;

‎tests/Core/UtilitiesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use InvalidArgumentException, ReflectionClass;
1818

1919
/**
20-
*
20+
* Tests the Utilities class
2121
*/
2222
class UtilitiesTest extends TestCase{
2323

‎tests/Providers/Live/OAuth1ProviderLiveTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace chillerlan\OAuthTest\Providers\Live;
1313

1414
/**
15+
* OAuth1 live API test
16+
*
1517
* @property \chillerlan\OAuth\Core\OAuth1Interface $provider
1618
*/
1719
abstract class OAuth1ProviderLiveTestAbstract extends OAuthProviderLiveTestAbstract{

‎tests/Providers/Live/OAuth2ProviderLiveTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use function time;
1818

1919
/**
20+
* OAuth2 live API test
21+
*
2022
* @property \chillerlan\OAuth\Core\OAuth2Interface $provider
2123
*/
2224
abstract class OAuth2ProviderLiveTestAbstract extends OAuthProviderLiveTestAbstract{

‎tests/Providers/Live/OAuthProviderLiveTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use function constant, sprintf;
2121

2222
/**
23+
* abstract OAuth live API test
24+
*
2325
* @property \chillerlan\OAuth\Core\OAuthInterface $provider
2426
*/
2527
abstract class OAuthProviderLiveTestAbstract extends ProviderLiveTestAbstract{

‎tests/Providers/ProviderLiveTestAbstract.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use function defined;
2020

2121
/**
22-
*
22+
* The abstract base class for all live API tests
2323
*/
2424
abstract class ProviderLiveTestAbstract extends ProviderUnitTestAbstract{
2525

@@ -28,7 +28,9 @@ abstract class ProviderLiveTestAbstract extends ProviderUnitTestAbstract{
2828
protected DotEnv $dotEnv;
2929
protected string $ENV_PREFIX;
3030

31-
/** a test username for live API tests, defined in .env as {ENV-PREFIX}_TESTUSER*/
31+
/**
32+
* a test username for live API tests, defined in `.env` as `<$provider::IDENTIFIER>_TESTUSER`
33+
*/
3234
protected string $TEST_USER = '';
3335

3436
/**

‎tests/Providers/ProviderLiveTestHttpClientFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
use function sprintf;
2424

2525
/**
26+
* A PSR-18 HTTP client factory for clients used in live API tests
2627
*
28+
* The phpunit constant `HTTP_CLIENT_FACTORY` should be set with a valid FQCN for a `HttpClientFactoryInterface`
29+
*
30+
* @see \chillerlan\PHPUnitHttp\HttpClientFactoryInterface
31+
* @link https://github.com/chillerlan/phpunit-http
2732
*/
2833
final class ProviderLiveTestHttpClientFactory implements HttpClientFactoryInterface{
2934

‎tests/Providers/ProviderTestLoggerFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use const JSON_UNESCAPED_SLASHES;
2020

2121
/**
22-
*
22+
* A simple PSR-3 logger factory used in provider tests
2323
*/
2424
final class ProviderTestLoggerFactory{
2525

‎tests/Providers/ProviderUnitTestAbstract.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
use function sprintf;
3838

3939
/**
40-
*
40+
* The abstract base class for all provider tests
4141
*/
4242
abstract class ProviderUnitTestAbstract extends TestCase{
4343
use HttpFactoryTrait;
@@ -57,6 +57,9 @@ abstract class ProviderUnitTestAbstract extends TestCase{
5757
protected const CFGDIR = self::PROJECT_ROOT.'/.config';
5858
protected const CACERT = self::PROJECT_ROOT.'/tests/cacert.pem';
5959

60+
/**
61+
* Initializes the unit test
62+
*/
6063
protected function setUp():void{
6164
ini_set('date.timezone', 'UTC');
6265

@@ -93,6 +96,9 @@ protected function setUp():void{
9396
* init dependencies
9497
*/
9598

99+
/**
100+
* Initializes the environment config (from `phpunit.xml`)
101+
*/
96102
protected function initConfig():void{
97103

98104
foreach(['TEST_ENVFILE'] as $constant){
@@ -103,6 +109,9 @@ protected function initConfig():void{
103109

104110
}
105111

112+
/**
113+
* Initializes an `OAuthOptions` instance
114+
*/
106115
protected function initOptions():OAuthOptions{
107116
$options = new OAuthOptions;
108117

@@ -114,6 +123,9 @@ protected function initOptions():OAuthOptions{
114123
return $options;
115124
}
116125

126+
/**
127+
* Initializes an `OAuthStorageInterface` instance
128+
*/
117129
protected function initStorage(OAuthOptions $options):OAuthStorageInterface{
118130
return new MemoryStorage($options);
119131
}
@@ -123,20 +135,29 @@ protected function initStorage(OAuthOptions $options):OAuthStorageInterface{
123135
* Reflection utilities
124136
*/
125137

138+
/**
139+
* Sets a property in the current provider instance with the given value
140+
*/
126141
final protected function setReflectionProperty(string $property, mixed $value):void{
127142
$this->reflection->getProperty($property)->setValue($this->provider, $value);
128143
}
129144

145+
/**
146+
* Returns the current value of the given propertyin the current provider instance
147+
*/
130148
final protected function getReflectionProperty(string $property):mixed{
131149
return $this->reflection->getProperty($property)->getValue($this->provider);
132150
}
133151

152+
/**
153+
* Invokes a method vith the given arguments in the current provider instance
154+
*/
134155
final protected function invokeReflectionMethod(string $method, array $args = []):mixed{
135156
return $this->reflection->getMethod($method)->invokeArgs($this->provider, $args);
136157
}
137158

138159
/**
139-
* returns the fully qualified class name (FQCN) of the test subject
160+
* Returns the fully qualified class name (FQCN) of the test subject
140161
*
141162
* @see \chillerlan\OAuthTest\Attributes\Provider
142163
*/
@@ -156,7 +177,7 @@ final protected function getProviderFQCN():string{
156177
*/
157178

158179
/**
159-
* creates a stupid simple ClientInterface that returns the given response instance
180+
* Creates a stupid simple `ClientInterface` that returns the given response instance
160181
*/
161182
protected function getMockHttpClient(ResponseInterface $response):ClientInterface{
162183
return new class ($response) implements ClientInterface{
@@ -174,7 +195,7 @@ public function sendRequest(RequestInterface $request):ResponseInterface{
174195
}
175196

176197
/**
177-
* sets a custom response in the mock http client and sets the client in the current provider
198+
* Sets a custom response in the mock http client and sets the client in the current provider
178199
*/
179200
protected function setMockResponse(ResponseInterface|StreamInterface $response):void{
180201

‎tests/Providers/ProviderUnitTestHttpClientFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
use Psr\Http\Message\ResponseFactoryInterface;
1818

1919
/**
20+
* A PSR-18 HTTP client factory for provider unit tests
2021
*
22+
* This factory just returns an echo client, that returns the given request
23+
*
24+
* @see \chillerlan\PHPUnitHttp\HttpClientFactoryInterface
25+
* @link https://github.com/chillerlan/phpunit-http
2126
*/
2227
final class ProviderUnitTestHttpClientFactory implements HttpClientFactoryInterface{
2328

‎tests/Providers/Unit/OAuth1ProviderUnitTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use function str_starts_with;
2020

2121
/**
22+
* OAuth1 unit test
23+
*
2224
* @property \chillerlan\OAuth\Core\OAuth1Interface $provider
2325
*/
2426
abstract class OAuth1ProviderUnitTestAbstract extends OAuthProviderUnitTestAbstract{

‎tests/Providers/Unit/OAuth2ProviderUnitTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use function base64_encode, implode, json_decode, json_encode;
2626

2727
/**
28+
* OAuth2 unit test
29+
*
2830
* @property \chillerlan\OAuth\Core\OAuth2Interface $provider
2931
*/
3032
abstract class OAuth2ProviderUnitTestAbstract extends OAuthProviderUnitTestAbstract{

‎tests/Providers/Unit/OAuthProviderUnitTestAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use function sprintf;
2828

2929
/**
30+
* abstract OAuth unit test
31+
*
3032
* @property \chillerlan\OAuth\Core\OAuthInterface $provider
3133
*/
3234
abstract class OAuthProviderUnitTestAbstract extends ProviderUnitTestAbstract{

‎tests/Storage/FileStorageEncryptedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use chillerlan\OAuth\OAuthOptions;
1515

1616
/**
17-
* Tests the file storage (encrypted)
17+
* Tests the `FileStorage` class (encrypted)
1818
*/
1919
final class FileStorageEncryptedTest extends FileStorageTest{
2020

‎tests/Storage/FileStorageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use const DIRECTORY_SEPARATOR;
1919

2020
/**
21-
* Tests the file storage
21+
* Tests the `FileStorage` class
2222
*/
2323
class FileStorageTest extends StorageTestAbstract{
2424

‎tests/Storage/MemoryStorageTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use chillerlan\OAuth\OAuthOptions;
1515
use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageInterface};
1616

17+
/**
18+
* Tests the `MemoryStorage` class
19+
*/
1720
final class MemoryStorageTest extends StorageTestAbstract{
1821

1922
protected function initStorage(OAuthOptions $options):OAuthStorageInterface{

‎tests/Storage/SessionStorageEncryptedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use chillerlan\OAuth\OAuthOptions;
1515

1616
/**
17-
* Tests the session storage (encrypted)
17+
* Tests the `SessionStorage` class (encrypted)
1818
*/
1919
final class SessionStorageEncryptedTest extends SessionStorageTest{
2020

‎tests/Storage/SessionStorageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use chillerlan\OAuth\Storage\{OAuthStorageInterface, SessionStorage};
1616

1717
/**
18-
* Tests the session storage
18+
* Tests the `SessionStorage` class
1919
*/
2020
class SessionStorageTest extends StorageTestAbstract{
2121

‎tests/Storage/StorageTestAbstract.php

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use ReflectionMethod;
2121
use function array_merge;
2222

23+
/**
24+
* The abstract storage test
25+
*/
2326
abstract class StorageTestAbstract extends TestCase{
2427

2528
protected const ENCRYPTION_KEY = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f';

0 commit comments

Comments
 (0)
Please sign in to comment.