From 8718f93f401c212eb10a26359ae998541a22f5ab Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 15:36:48 -0500 Subject: [PATCH 1/8] [SDK-3669] Add StoreInterface bridge support for Laravel Sessions --- composer.json | 2 +- src/Auth/Guard.php | 2 +- src/Auth0.php | 35 +++- src/Cache/LaravelCacheItem.php | 86 ++++++++++ src/Cache/LaravelCachePool.php | 180 +++++++++++++++++++++ src/Contract/Event/Configuration/Built.php | 33 ++++ src/Event/Configuration/Built.php | 42 +++++ src/Store/LaravelSession.php | 155 ++++++++++++++++++ 8 files changed, 532 insertions(+), 3 deletions(-) create mode 100644 src/Cache/LaravelCacheItem.php create mode 100644 src/Cache/LaravelCachePool.php create mode 100644 src/Contract/Event/Configuration/Built.php create mode 100644 src/Event/Configuration/Built.php create mode 100644 src/Store/LaravelSession.php diff --git a/composer.json b/composer.json index 52a6bf71..9524c152 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "pestphp/pest": "^1.21", "pestphp/pest-plugin-laravel": "^1.2", "phpstan/phpstan": "^1.7", - "phpstan/phpstan-strict-rules": "^1.3", + "phpstan/phpstan-strict-rules": "1.4.3", "phpunit/phpunit": "^9.5", "rector/rector": "^0.13.6", "wikimedia/composer-merge-plugin": "^2.0" diff --git a/src/Auth/Guard.php b/src/Auth/Guard.php index 531c589e..bd5b84a2 100644 --- a/src/Auth/Guard.php +++ b/src/Auth/Guard.php @@ -127,7 +127,7 @@ public function hasScope( $state = $this->getState(); return in_array($scope, $state->getAccessTokenScope() ?? [], true); } - + /** * Always returns false to keep third-party apps happy */ diff --git a/src/Auth0.php b/src/Auth0.php index 09217ec8..06b919cd 100644 --- a/src/Auth0.php +++ b/src/Auth0.php @@ -4,6 +4,9 @@ namespace Auth0\Laravel; +use Auth0\Laravel\Cache\LaravelCachePool; +use Auth0\Laravel\Store\LaravelSession; + /** * Service that provides access to the Auth0 SDK. */ @@ -54,7 +57,37 @@ public function setSdk( public function getConfiguration(): \Auth0\SDK\Configuration\SdkConfiguration { if ($this->configuration === null) { - $this->configuration = new \Auth0\SDK\Configuration\SdkConfiguration(app()->make('config')->get('auth0')); + $config = app()->make('config')->get('auth0'); + + if (! isset($config['tokenCache']) || ! isset($config['managementTokenCache'])) { + $cache = new LaravelCachePool(); + + if (! isset($config['tokenCache'])) { + $config['tokenCache'] = $cache; + } + + if (! isset($config['managementTokenCache'])) { + $config['managementTokenCache'] = $cache; + } + } + + $configuration = new \Auth0\SDK\Configuration\SdkConfiguration($config); + + // If no sessionStorage is defined, use an LaravelSession store instance. + if (! isset($config['sessionStorage'])) { + $configuration->setSessionStorage(new LaravelSession($configuration, $configuration->getSessionStorageId())); + } + + // If no transientStorage is defined, use an LaravelSession store instance. + if (! isset($config['transientStorage'])) { + $configuration->setTransientStorage(new LaravelSession($configuration, $configuration->getSessionStorageId())); + } + + // Give apps an opportunity to mutate the configuration before applying it. + $event = new \Auth0\Laravel\Event\Configuration\Built($configuration); + event($event); + + $this->configuration = $event->getConfiguration(); } return $this->configuration; diff --git a/src/Cache/LaravelCacheItem.php b/src/Cache/LaravelCacheItem.php new file mode 100644 index 00000000..0677e9e2 --- /dev/null +++ b/src/Cache/LaravelCacheItem.php @@ -0,0 +1,86 @@ +key; + } + + public function get(): mixed + { + return $this->value; + } + + public function isHit(): bool + { + return $this->is_hit; + } + + public function set(mixed $value): static + { + $this->value = $value; + $this->is_hit = true; + return $this; + } + + public function expiresAt(?DateTimeInterface $expiration): static + { + if ($expiration instanceof DateTimeInterface) { + $this->expires = $expiration->getTimestamp(); + return $this; + } + + $this->expires = $expiration; + return $this; + } + + /** + * @param DateInterval|int|null $time + */ + public function expiresAfter(DateInterval|int|null $time): static + { + if ($time === null) { + $this->expires = null; + return $this; + } + + if ($time instanceof DateInterval) { + $dateTime = new DateTime(); + $dateTime->add($time); + $this->expires = $dateTime->getTimestamp(); + return $this; + } + + $this->expires = time() + $time; + return $this; + } + + public function expirationTimestamp(): ?int + { + return $this->expires; + } + + public static function miss(string $key): self + { + return new self($key, null, false); + } +} diff --git a/src/Cache/LaravelCachePool.php b/src/Cache/LaravelCachePool.php new file mode 100644 index 00000000..6ce0a947 --- /dev/null +++ b/src/Cache/LaravelCachePool.php @@ -0,0 +1,180 @@ + + */ + private array $deferred = []; + + public function __construct() + { + $this->manager = app()->make(\Illuminate\Cache\CacheManager::class); + } + + public function getItem(string $key): CacheItemInterface + { + $value = $this->getStore()->get($key); + + if ($value === false) { + return LaravelCacheItem::miss($key); + } + + return $this->createItem($key, $value); + } + + /** + * @param string[] $keys + * + * @return CacheItemInterface[] + */ + public function getItems(array $keys = []): iterable + { + if ($keys === []) { + return []; + } + + $results = $this->getStore()->many($keys); + $items = []; + + foreach ($results as $key => $value) { + $key = (string) $key; + $items[$key] = $this->createItem($key, $value); + } + + return $items; + } + + public function hasItem(string $key): bool + { + return $this->getItem($key) + ->isHit(); + } + + public function clear(): bool + { + $this->deferred = []; + return $this->getStore()->flush(); + } + + public function deleteItem(string $key): bool + { + return $this->getStore()->forget($key); + } + + public function deleteItems(array $keys): bool + { + $deleted = true; + + foreach ($keys as $key) { + if (! $this->deleteItem($key)) { + $deleted = false; + } + } + + return $deleted; + } + + public function save(CacheItemInterface $item): bool + { + if (! $item instanceof LaravelCacheItem) { + return false; + } + + $value = serialize($item->get()); + $key = $item->getKey(); + $expires = $item->expirationTimestamp(); + $ttl = 0; + + if ($expires !== null) { + if ($expires <= time()) { + return $this->deleteItem($key); + } + + $ttl = $expires - time(); + } + + return $this->getStore()->put($key, $value, $ttl); + } + + public function saveDeferred(CacheItemInterface $item): bool + { + if (! $item instanceof LaravelCacheItem) { + return false; + } + + $this->deferred[$item->getKey()] = [ + 'item' => $item, + 'expiration' => $item->expirationTimestamp(), + ]; + + return true; + } + + public function commit(): bool + { + $success = true; + + foreach (array_keys($this->deferred) as $singleDeferred) { + $item = $this->getDeferred((string) $singleDeferred); + + if ($item !== null && ! $this->save($item)) { + $success = false; + } + } + + $this->deferred = []; + return $success; + } + + private function getStore(): \Illuminate\Contracts\Cache\Store + { + return $this->manager->getStore(); + } + + private function createItem(string $key, mixed $value): CacheItemInterface + { + if (! is_string($value)) { + return LaravelCacheItem::miss($key); + } + + $value = unserialize($value); + + if ($value === false || $value !== 'b:0;') { + return LaravelCacheItem::miss($key); + } + + return new LaravelCacheItem($key, $value, true); + } + + private function getDeferred(string $key): ?CacheItemInterface + { + if (! isset($this->deferred[$key])) { + return null; + } + + $deferred = $this->deferred[$key]; + $item = clone $deferred['item']; + $expires = $deferred['expiration']; + + if ($expires !== null && $expires <= time()) { + unset($this->deferred[$key]); + return null; + } + + return $item; + } +} diff --git a/src/Contract/Event/Configuration/Built.php b/src/Contract/Event/Configuration/Built.php new file mode 100644 index 00000000..eaa601a4 --- /dev/null +++ b/src/Contract/Event/Configuration/Built.php @@ -0,0 +1,33 @@ +configuration = $configuration; + } + + /** + * @inheritdoc + */ + public function setConfiguration( + SdkConfiguration $configuration + ): self { + $this->configuration = $configuration; + return $this; + } + + /** + * @inheritdoc + */ + public function getConfiguration(): SdkConfiguration + { + return $this->configuration; + } +} diff --git a/src/Store/LaravelSession.php b/src/Store/LaravelSession.php new file mode 100644 index 00000000..3ca4e98f --- /dev/null +++ b/src/Store/LaravelSession.php @@ -0,0 +1,155 @@ +configuration = $configuration; + $this->sessionPrefix = $sessionPrefix; + } + + /** + * Dispatch event to toggle state deferrance. + * + * @param bool $deferring Whether to defer persisting the storage state. + */ + public function defer( + bool $deferring + ): void { + return; + } + + /** + * Dispatch event to set the value of a key-value pair. + * + * @param string $key Session key to set. + * @param mixed $value Value to use. + */ + public function set( + string $key, + $value + ): void { + $this->boot(); + $this->getStore()->put($this->getPrefixedKey($key), $value); + } + + /** + * Dispatch event to retrieve the value of a key-value pair. + * + * @param string $key Session key to query. + * @param mixed $default Default to return if nothing was found. + * + * @return mixed + */ + public function get( + string $key, + $default = null + ) { + $this->boot(); + return $this->getStore()->get($this->getPrefixedKey($key), $default); + } + + /** + * Dispatch event to clear all key-value pairs. + */ + public function purge(): void + { + $this->boot(); + + // It would be unwise for us to simply flush() a session here, as it is shared with the app ecosystem. + // Instead, iterate through the session data, and if they key is prefixed with our assigned string, delete it. + + $pairs = $this->getStore()->all(); + $prefix = $this->sessionPrefix . '_'; + + foreach (array_keys($pairs) as $key) { + if (substr($key, 0, strlen($prefix)) === $prefix) { + $this->delete($key); + } + } + } + + /** + * Dispatch event to delete key-value pair. + * + * @param string $key Session key to delete. + */ + public function delete( + string $key + ): void { + $this->boot(); + $this->getStore()->forget($this->getPrefixedKey($key)); + } + + /** + * Dispatch event to alert that a session should be prepared for an incoming request. + */ + private function boot(): void + { + if (! $this->booted) { + if (!$this->getStore()->isStarted()) { + $this->getStore()->start(); + } + + $this->booted = true; + } + + return; + } + + private function getStore(): \Illuminate\Session\Store + { + $request = request(); + + if ($request instanceof \Illuminate\Http\Request) { + return $request->session(); + } + + throw new Exception("A cache must be configured."); + } + + private function getPrefixedKey(string $key): string + { + if ($this->sessionPrefix !== '') { + return $this->sessionPrefix . '_' . $key; + } + + return $key; + } +} From 3aad0c6ea06e1dacd9457c3dc5e511ff22bf1e2f Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 15:59:18 -0500 Subject: [PATCH 2/8] PHP 7.4 fixes --- src/Cache/LaravelCacheItem.php | 16 +++++++++++----- src/Cache/LaravelCachePool.php | 23 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Cache/LaravelCacheItem.php b/src/Cache/LaravelCacheItem.php index 0677e9e2..cdf66e04 100644 --- a/src/Cache/LaravelCacheItem.php +++ b/src/Cache/LaravelCacheItem.php @@ -12,12 +12,18 @@ final class LaravelCacheItem implements CacheItemInterface { private ?int $expires = null; + private string $key; + private mixed $value; + private bool $is_hit; public function __construct( - private string $key, - private mixed $value, - private bool $is_hit + string $key, + mixed $value, + bool $is_hit ) { + $this->key = $key; + $this->value = $value; + $this->is_hit = $is_hit; } public function getKey(): string @@ -42,7 +48,7 @@ public function set(mixed $value): static return $this; } - public function expiresAt(?DateTimeInterface $expiration): static + public function expiresAt(mixed $expiration): static { if ($expiration instanceof DateTimeInterface) { $this->expires = $expiration->getTimestamp(); @@ -56,7 +62,7 @@ public function expiresAt(?DateTimeInterface $expiration): static /** * @param DateInterval|int|null $time */ - public function expiresAfter(DateInterval|int|null $time): static + public function expiresAfter(mixed $time): static { if ($time === null) { $this->expires = null; diff --git a/src/Cache/LaravelCachePool.php b/src/Cache/LaravelCachePool.php index 6ce0a947..fc8b95db 100644 --- a/src/Cache/LaravelCachePool.php +++ b/src/Cache/LaravelCachePool.php @@ -25,7 +25,14 @@ public function __construct() $this->manager = app()->make(\Illuminate\Cache\CacheManager::class); } - public function getItem(string $key): CacheItemInterface + /** + * Returns a Cache Item representing the specified key. + * + * @param string $key The key for which to return the corresponding Cache Item. + * + * @return CacheItemInterface + */ + public function getItem($key) { $value = $this->getStore()->get($key); @@ -58,7 +65,12 @@ public function getItems(array $keys = []): iterable return $items; } - public function hasItem(string $key): bool + /** + * @param string $key The key for which to return the corresponding Cache Item. + * + * @return bool + */ + public function hasItem($key): bool { return $this->getItem($key) ->isHit(); @@ -70,7 +82,12 @@ public function clear(): bool return $this->getStore()->flush(); } - public function deleteItem(string $key): bool + /** + * @param string $key The key for which to return the corresponding Cache Item. + * + * @return bool + */ + public function deleteItem($key): bool { return $this->getStore()->forget($key); } From 86b9f7d0457b6233ff80a691382c65d348ca725a Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:11:01 -0500 Subject: [PATCH 3/8] Drop PHP 7.4 support out of necessity for type definitions conflict --- .github/workflows/tests.yml | 55 ++++------------------------------ composer.json | 1 + phpstan.neon.dist | 12 -------- src/Cache/LaravelCachePool.php | 7 +++-- 4 files changed, 10 insertions(+), 65 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87ea8d69..9df9d037 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: max-parallel: 10 matrix: - php: ["7.4", "8.0", "8.1"] + php: ["8.0", "8.1", "8.2"] steps: - name: Checkout code @@ -52,7 +52,7 @@ jobs: strategy: max-parallel: 10 matrix: - php: ["7.4", "8.0", "8.1"] + php: ["8.0", "8.1", "8.2"] steps: - name: Set up PHP ${{ matrix.php }} @@ -99,7 +99,7 @@ jobs: fail-fast: true max-parallel: 10 matrix: - php: ["7.4", "8.0", "8.1"] + php: ["8.0", "8.1", "8.2"] steps: - name: Set up PHP ${{ matrix.php }} @@ -132,48 +132,6 @@ jobs: - name: Execute PHPStan run: vendor/bin/phpstan analyze --no-progress - # psalm: - # name: Psalm - # runs-on: ubuntu-latest - # needs: ["dependencies"] - - # strategy: - # fail-fast: true - # max-parallel: 10 - # matrix: - # php: ["7.4", "8.0", "8.1"] - - # steps: - # - name: Set up PHP ${{ matrix.php }} - # uses: shivammathur/setup-php@v2 - # with: - # php-version: ${{ matrix.php }} - # coverage: none - # extensions: mbstring - # env: - # update: true - # COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # - name: Checkout code - # uses: actions/checkout@v3 - - # - name: Get composer cache directory - # id: composer-cache - # run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - # - name: Cache dependencies - # uses: actions/cache@v2 - # with: - # path: ${{ steps.composer-cache.outputs.dir }} - # key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-${{ github.run_id }} - # restore-keys: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-${{ github.run_id }} - - # - name: Install dependencies - # run: composer install --prefer-dist - - # - name: Execute Psalm - # run: vendor/bin/psalm --no-progress - pint: name: Laravel Pint runs-on: ubuntu-latest @@ -183,7 +141,7 @@ jobs: fail-fast: true max-parallel: 10 matrix: - php: ["8.0", "8.1"] + php: ["8.0", "8.1", "8.2"] steps: - name: Set up PHP ${{ matrix.php }} @@ -213,9 +171,6 @@ jobs: - name: Install dependencies run: composer install --prefer-dist - - name: Install Laravel Pint - run: composer require laravel/pint:* --dev --with-all-dependencies - - name: Execute Laravel Pint run: vendor/bin/pint --test @@ -228,7 +183,7 @@ jobs: fail-fast: true max-parallel: 10 matrix: - php: ["7.4", "8.0", "8.1"] + php: ["8.0", "8.1", "8.2"] steps: - name: Set up PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index 9524c152..9c9650f7 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "illuminate/contracts": "^8.0 || ^9.0", "illuminate/http": "^8.0 || ^9.0", "illuminate/support": "^8.0 || ^9.0", + "laravel/pint": "^1.2", "spatie/laravel-package-tools": "^1.9" }, "require-dev": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 048f34c2..550f8aad 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,21 +11,9 @@ parameters: - tests/constants.php ignoreErrors: - - '#Function (app|auth|event|redirect) not found.#' - - '#Constructor in (.*) has parameter (.*) with default value.#' - - '#Constructor in (.*) has parameter (.*) with null as default value.#' - - '#Method (.*) has parameter (.*) with a nullable type declaration.#' - - '#Method (.*) has parameter (.*) with null as default value.#' - - '#Method (.*) has a nullable return type declaration.#' - - '#Language construct isset\(\) should not be used.#' - '#Method (.*) has parameter (.*) with no value type specified in iterable type array.#' - - '#not allowed to extend#' - '#Cannot call method (.*) on mixed#' - '#no value type specified in iterable type array.#' - - '#is not final, but since the containing class is abstract, it should be.#' - - '#Class "Auth0\\Login\\Exception\\(.*)" is not allowed to extend "Exception".#' - - '#Class "Auth0\\Laravel\\Exception\\(.*)" is not allowed to extend "Exception".#' - '#Call to an undefined method Illuminate\\(.*).#' - - '#\$hash is never read, only written.#' reportUnmatchedIgnoredErrors: false diff --git a/src/Cache/LaravelCachePool.php b/src/Cache/LaravelCachePool.php index fc8b95db..0e9dbc72 100644 --- a/src/Cache/LaravelCachePool.php +++ b/src/Cache/LaravelCachePool.php @@ -32,7 +32,8 @@ public function __construct() * * @return CacheItemInterface */ - public function getItem($key) + + public function getItem(mixed $key) { $value = $this->getStore()->get($key); @@ -70,7 +71,7 @@ public function getItems(array $keys = []): iterable * * @return bool */ - public function hasItem($key): bool + public function hasItem(mixed $key): bool { return $this->getItem($key) ->isHit(); @@ -87,7 +88,7 @@ public function clear(): bool * * @return bool */ - public function deleteItem($key): bool + public function deleteItem(mixed $key): bool { return $this->getStore()->forget($key); } From 9bac9f6f5a4aa0efc3a43af8217280de0380bc46 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:12:50 -0500 Subject: [PATCH 4/8] Drop 7.4 check from Snyk --- .github/workflows/security.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 169453f8..85d8ea84 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -13,7 +13,7 @@ jobs: strategy: max-parallel: 10 matrix: - php: ["7.4", "8.0", "8.1"] + php: "8.0", "8.1", "8.2"] if: (github.actor != 'dependabot[bot]') steps: diff --git a/composer.json b/composer.json index 9c9650f7..02645cf4 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ ], "homepage": "https://github.com/auth0/laravel-auth0", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-filter": "*", "ext-json": "*", "ext-mbstring": "*", From 8c4977032db3fd2c8ae3a527fc916b1c1fba36ea Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:22:19 -0500 Subject: [PATCH 5/8] Move Laravel/Pint into dev-dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 02645cf4..40431094 100644 --- a/composer.json +++ b/composer.json @@ -38,11 +38,11 @@ "illuminate/contracts": "^8.0 || ^9.0", "illuminate/http": "^8.0 || ^9.0", "illuminate/support": "^8.0 || ^9.0", - "laravel/pint": "^1.2", "spatie/laravel-package-tools": "^1.9" }, "require-dev": { "laravel/laravel": "^8.4.4 || ^9.0", + "laravel/pint": "^1.2", "nunomaduro/larastan": "^1.0", "nyholm/psr7": "^1.4", "orchestra/testbench": "6.25.0", From 54ba79b73ef7609bdbc8c0efb5262bf88d7edd06 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:22:32 -0500 Subject: [PATCH 6/8] Fix PHP 8+ getItem definition for CacheItemPoolInterface --- src/Cache/LaravelCachePool.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Cache/LaravelCachePool.php b/src/Cache/LaravelCachePool.php index 0e9dbc72..693d6bc1 100644 --- a/src/Cache/LaravelCachePool.php +++ b/src/Cache/LaravelCachePool.php @@ -25,15 +25,7 @@ public function __construct() $this->manager = app()->make(\Illuminate\Cache\CacheManager::class); } - /** - * Returns a Cache Item representing the specified key. - * - * @param string $key The key for which to return the corresponding Cache Item. - * - * @return CacheItemInterface - */ - - public function getItem(mixed $key) + public function getItem(string $key): CacheItemInterface { $value = $this->getStore()->get($key); From a74bb295cae0f68086a3abaf10fb3a6bcb397612 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:28:13 -0500 Subject: [PATCH 7/8] Add EBS to developer dependencies --- composer.json | 1 + ecs.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 ecs.php diff --git a/composer.json b/composer.json index 40431094..d0c27ad2 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "phpstan/phpstan-strict-rules": "1.4.3", "phpunit/phpunit": "^9.5", "rector/rector": "^0.13.6", + "symplify/easy-coding-standard": "^11.1", "wikimedia/composer-merge-plugin": "^2.0" }, "autoload": { diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..140eed84 --- /dev/null +++ b/ecs.php @@ -0,0 +1,89 @@ +sets([SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]); + + $ecsConfig->paths([ + __DIR__ . '/bin', + __DIR__ . '/src', + __DIR__ . '/packages', + __DIR__ . '/packages-tests', + __DIR__ . '/rules', + __DIR__ . '/rules-tests', + __DIR__ . '/tests', + __DIR__ . '/utils', + __DIR__ . '/config', + __DIR__ . '/ecs.php', + __DIR__ . '/easy-ci.php', + __DIR__ . '/rector.php', + __DIR__ . '/scoper.php', + __DIR__ . '/build/build-preload.php', + ]); + + $ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, [ + 'allow_mixed' => true, + ]); + + $ecsConfig->ruleWithConfiguration(GeneralPhpdocAnnotationRemoveFixer::class, [ + 'annotations' => [ + 'throw', + 'throws', + 'author', + 'authors', + 'package', + 'group', + 'required', + 'phpstan-ignore-line', + 'phpstan-ignore-next-line', + ], + ]); + + $ecsConfig->rule(StaticLambdaFixer::class); + + $ecsConfig->skip([ + '*/Source/*', + '*/Fixture/*', + '*/Expected/*', + + // buggy - @todo fix on Symplify master + DocBlockLineLengthFixer::class, + + PhpdocTypesFixer::class => [ + // double to Double false positive + __DIR__ . '/rules/Php74/Rector/Double/RealToFloatTypeCastRector.php', + // skip for enum types + __DIR__ . '/rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php', + ], + + // breaking and handled better by Rector PHPUnit code quality set, removed in symplify dev-main + PhpUnitStrictFixer::class, + + // skip add space on &$variable + FunctionTypehintSpaceFixer::class => [ + __DIR__ . '/src/PhpParser/Printer/BetterStandardPrinter.php', + __DIR__ . '/src/DependencyInjection/Loader/Configurator/RectorServiceConfigurator.php', + __DIR__ . '/rules/Php70/EregToPcreTransformer.php', + ], + + AssignmentInConditionSniff::class . '.FoundInWhileCondition', + + // null on purpose as no change + PhpdocNoEmptyReturnFixer::class => [ + __DIR__ . '/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php', + ], + ]); +}; From ebb2c40dcd09f7b771c3d09afc42c7decd2b1335 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 10 Oct 2022 16:32:40 -0500 Subject: [PATCH 8/8] Code style pass --- src/Auth/Guard.php | 56 ++++++++++++------- src/Auth/User/Provider.php | 27 ++++----- src/Auth/User/Repository.php | 18 ++---- src/Auth0.php | 22 +++++--- src/Cache/LaravelCacheItem.php | 10 ++-- src/Cache/LaravelCachePool.php | 22 ++++---- src/Configuration.php | 12 ++-- src/Contract/Auth/Guard.php | 9 +-- src/Contract/Auth/User/Provider.php | 4 +- src/Contract/Auth/User/Repository.php | 8 +-- src/Contract/Auth0.php | 8 +-- src/Contract/Configuration.php | 10 +--- src/Contract/Event/Configuration/Built.php | 8 +-- .../Event/Stateful/AuthenticationFailed.php | 13 +---- .../Stateful/AuthenticationSucceeded.php | 8 +-- .../Exception/Stateful/CallbackException.php | 5 +- .../Http/Controller/Stateful/Callback.php | 4 +- .../Http/Controller/Stateful/Login.php | 4 +- .../Http/Controller/Stateful/Logout.php | 4 +- .../Http/Middleware/Stateful/Authenticate.php | 8 +-- .../Stateful/AuthenticateOptional.php | 8 +-- .../Http/Middleware/Stateless/Authorize.php | 10 +--- .../Stateless/AuthorizeOptional.php | 8 +-- src/Contract/Model/User.php | 34 ++--------- src/Contract/ServiceProvider.php | 4 +- src/Contract/StateInstance.php | 28 +++------- src/Event/Configuration/Built.php | 10 ++-- src/Event/Stateful/AuthenticationFailed.php | 16 ++---- .../Stateful/AuthenticationSucceeded.php | 10 ++-- src/Exception/Stateful/CallbackException.php | 6 +- src/Http/Controller/Stateful/Callback.php | 19 +++++-- src/Http/Controller/Stateful/Login.php | 5 +- src/Http/Controller/Stateful/Logout.php | 20 ++++--- src/Http/Middleware/Stateful/Authenticate.php | 15 +++-- .../Stateful/AuthenticateOptional.php | 15 +++-- src/Http/Middleware/Stateless/Authorize.php | 16 +++--- .../Stateless/AuthorizeOptional.php | 15 +++-- src/Model/User.php | 38 +++++-------- src/ServiceProvider.php | 52 +++++++++++++---- src/StateInstance.php | 35 +++++------- src/Store/LaravelSession.php | 47 ++++++++-------- src/Traits/ActingAsAuth0User.php | 12 +--- 42 files changed, 288 insertions(+), 395 deletions(-) diff --git a/src/Auth/Guard.php b/src/Auth/Guard.php index bd5b84a2..889b9ba4 100644 --- a/src/Auth/Guard.php +++ b/src/Auth/Guard.php @@ -30,10 +30,10 @@ public function __construct( /** * @inheritdoc */ - public function login( - \Illuminate\Contracts\Auth\Authenticatable $user - ): self { - $this->getState()->setUser($user); + public function login(\Illuminate\Contracts\Auth\Authenticatable $user): self + { + $this->getState() + ->setUser($user); return $this; } @@ -42,7 +42,8 @@ public function login( */ public function logout(): self { - $this->getState()->setUser(null); + $this->getState() + ->setUser(null); app(\Auth0\Laravel\Auth0::class)->getSdk()->clear(); return $this; } @@ -68,7 +69,8 @@ public function guest(): bool */ public function user(): ?\Illuminate\Contracts\Auth\Authenticatable { - return $this->getState()->getUser() ?? $this->getUserFromToken() ?? $this->getUserFromSession() ?? null; + return $this->getState() + ->getUser() ?? $this->getUserFromToken() ?? $this->getUserFromSession() ?? null; } /** @@ -79,7 +81,8 @@ public function id() $response = null; if ($this->user() !== null) { - $id = $this->user()->getAuthIdentifier(); + $id = $this->user() + ->getAuthIdentifier(); if (is_string($id) || is_int($id)) { $response = $id; @@ -94,19 +97,18 @@ public function id() * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function validate( - array $credentials = [] - ): bool { + public function validate(array $credentials = []): bool + { return false; } /** * @inheritdoc */ - public function setUser( - \Illuminate\Contracts\Auth\Authenticatable $user - ): self { - $user = $this->getState()->setUser($user); + public function setUser(\Illuminate\Contracts\Auth\Authenticatable $user): self + { + $user = $this->getState() + ->setUser($user); return $this; } @@ -115,15 +117,14 @@ public function setUser( */ public function hasUser(): bool { - return ! is_null($this->getState()->getUser()); + return $this->getState()->getUser() !== null; } /** * @inheritdoc */ - public function hasScope( - string $scope - ): bool { + public function hasScope(string $scope): bool + { $state = $this->getState(); return in_array($scope, $state->getAccessTokenScope() ?? [], true); } @@ -151,14 +152,25 @@ private function getUserFromToken(): ?\Illuminate\Contracts\Auth\Authenticatable try { // Attempt to decode the bearer token. - $decoded = app(\Auth0\Laravel\Auth0::class)->getSdk()->decode($token, null, null, null, null, null, null, \Auth0\SDK\Token::TYPE_TOKEN)->toArray(); + $decoded = app(\Auth0\Laravel\Auth0::class)->getSdk()->decode( + $token, + null, + null, + null, + null, + null, + null, + \Auth0\SDK\Token::TYPE_TOKEN + )->toArray(); } catch (\Auth0\SDK\Exception\InvalidTokenException $invalidToken) { // Invalid bearer token. return null; } // Query the UserProvider to retrieve tue user for the token. - $user = $this->getProvider()->getRepository()->fromAccessToken($decoded); + $user = $this->getProvider() + ->getRepository() + ->fromAccessToken($decoded); // Was a user retrieved successfully? if ($user !== null) { @@ -195,7 +207,9 @@ private function getUserFromSession(): ?\Illuminate\Contracts\Auth\Authenticatab } // Query the UserProvider to retrieve tue user for the session. - $user = $this->getProvider()->getRepository()->fromSession($session->user); + $user = $this->getProvider() + ->getRepository() + ->fromSession($session->user); // Was a user retrieved successfully? if ($user !== null) { diff --git a/src/Auth/User/Provider.php b/src/Auth/User/Provider.php index 3bb74a20..c53c3975 100644 --- a/src/Auth/User/Provider.php +++ b/src/Auth/User/Provider.php @@ -14,9 +14,8 @@ final class Provider implements \Auth0\Laravel\Contract\Auth\User\Provider, \Ill /** * @inheritdoc */ - public function __construct( - \Auth0\Laravel\Contract\Auth\User\Repository $repository - ) { + public function __construct(\Auth0\Laravel\Contract\Auth\User\Repository $repository) + { $this->repository = $repository; } @@ -25,9 +24,8 @@ public function __construct( * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function retrieveById( - $identifier - ): ?\Illuminate\Contracts\Auth\Authenticatable { + public function retrieveById($identifier): ?\Illuminate\Contracts\Auth\Authenticatable + { return null; } @@ -36,10 +34,8 @@ public function retrieveById( * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function retrieveByToken( - $identifier, - $token - ): ?\Illuminate\Contracts\Auth\Authenticatable { + public function retrieveByToken($identifier, $token): ?\Illuminate\Contracts\Auth\Authenticatable + { return null; } @@ -48,9 +44,8 @@ public function retrieveByToken( * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function retrieveByCredentials( - array $credentials - ): ?\Illuminate\Contracts\Auth\Authenticatable { + public function retrieveByCredentials(array $credentials): ?\Illuminate\Contracts\Auth\Authenticatable + { return null; } @@ -71,10 +66,8 @@ public function validateCredentials( * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function updateRememberToken( - \Illuminate\Contracts\Auth\Authenticatable $user, - $token - ): void { + public function updateRememberToken(\Illuminate\Contracts\Auth\Authenticatable $user, $token): void + { } /** diff --git a/src/Auth/User/Repository.php b/src/Auth/User/Repository.php index 7e7295a4..1777cf74 100644 --- a/src/Auth/User/Repository.php +++ b/src/Auth/User/Repository.php @@ -9,22 +9,16 @@ final class Repository implements \Auth0\Laravel\Contract\Auth\User\Repository /** * @inheritdoc */ - public function fromSession( - array $user - ): ?\Illuminate\Contracts\Auth\Authenticatable { - return new \Auth0\Laravel\Model\Stateful\User( - $user - ); + public function fromSession(array $user): ?\Illuminate\Contracts\Auth\Authenticatable + { + return new \Auth0\Laravel\Model\Stateful\User($user); } /** * @inheritdoc */ - public function fromAccessToken( - array $user - ): ?\Illuminate\Contracts\Auth\Authenticatable { - return new \Auth0\Laravel\Model\Stateless\User( - $user - ); + public function fromAccessToken(array $user): ?\Illuminate\Contracts\Auth\Authenticatable + { + return new \Auth0\Laravel\Model\Stateless\User($user); } } diff --git a/src/Auth0.php b/src/Auth0.php index 06b919cd..1deb431c 100644 --- a/src/Auth0.php +++ b/src/Auth0.php @@ -43,9 +43,8 @@ public function getSdk(): \Auth0\SDK\Contract\Auth0Interface /** * @inheritdoc */ - public function setSdk( - \Auth0\SDK\Contract\Auth0Interface $sdk - ): self { + public function setSdk(\Auth0\SDK\Contract\Auth0Interface $sdk): self + { $this->sdk = $sdk; $this->setSdkTelemetry(); return $this; @@ -57,7 +56,9 @@ public function setSdk( public function getConfiguration(): \Auth0\SDK\Configuration\SdkConfiguration { if ($this->configuration === null) { - $config = app()->make('config')->get('auth0'); + $config = app() + ->make('config') + ->get('auth0'); if (! isset($config['tokenCache']) || ! isset($config['managementTokenCache'])) { $cache = new LaravelCachePool(); @@ -75,12 +76,16 @@ public function getConfiguration(): \Auth0\SDK\Configuration\SdkConfiguration // If no sessionStorage is defined, use an LaravelSession store instance. if (! isset($config['sessionStorage'])) { - $configuration->setSessionStorage(new LaravelSession($configuration, $configuration->getSessionStorageId())); + $configuration->setSessionStorage( + new LaravelSession($configuration, $configuration->getSessionStorageId()) + ); } // If no transientStorage is defined, use an LaravelSession store instance. if (! isset($config['transientStorage'])) { - $configuration->setTransientStorage(new LaravelSession($configuration, $configuration->getSessionStorageId())); + $configuration->setTransientStorage( + new LaravelSession($configuration, $configuration->getSessionStorageId()) + ); } // Give apps an opportunity to mutate the configuration before applying it. @@ -96,9 +101,8 @@ public function getConfiguration(): \Auth0\SDK\Configuration\SdkConfiguration /** * @inheritdoc */ - public function setConfiguration( - \Auth0\SDK\Configuration\SdkConfiguration $configuration - ): self { + public function setConfiguration(\Auth0\SDK\Configuration\SdkConfiguration $configuration): self + { $this->configuration = $configuration; return $this; } diff --git a/src/Cache/LaravelCacheItem.php b/src/Cache/LaravelCacheItem.php index cdf66e04..258f2def 100644 --- a/src/Cache/LaravelCacheItem.php +++ b/src/Cache/LaravelCacheItem.php @@ -12,15 +12,15 @@ final class LaravelCacheItem implements CacheItemInterface { private ?int $expires = null; + private string $key; + private mixed $value; + private bool $is_hit; - public function __construct( - string $key, - mixed $value, - bool $is_hit - ) { + public function __construct(string $key, mixed $value, bool $is_hit) + { $this->key = $key; $this->value = $value; $this->is_hit = $is_hit; diff --git a/src/Cache/LaravelCachePool.php b/src/Cache/LaravelCachePool.php index 693d6bc1..d3d0dc26 100644 --- a/src/Cache/LaravelCachePool.php +++ b/src/Cache/LaravelCachePool.php @@ -22,12 +22,14 @@ final class LaravelCachePool implements CacheItemPoolInterface public function __construct() { - $this->manager = app()->make(\Illuminate\Cache\CacheManager::class); + $this->manager = app() + ->make(\Illuminate\Cache\CacheManager::class); } public function getItem(string $key): CacheItemInterface { - $value = $this->getStore()->get($key); + $value = $this->getStore() + ->get($key); if ($value === false) { return LaravelCacheItem::miss($key); @@ -47,7 +49,8 @@ public function getItems(array $keys = []): iterable return []; } - $results = $this->getStore()->many($keys); + $results = $this->getStore() + ->many($keys); $items = []; foreach ($results as $key => $value) { @@ -60,8 +63,6 @@ public function getItems(array $keys = []): iterable /** * @param string $key The key for which to return the corresponding Cache Item. - * - * @return bool */ public function hasItem(mixed $key): bool { @@ -72,17 +73,17 @@ public function hasItem(mixed $key): bool public function clear(): bool { $this->deferred = []; - return $this->getStore()->flush(); + return $this->getStore() + ->flush(); } /** * @param string $key The key for which to return the corresponding Cache Item. - * - * @return bool */ public function deleteItem(mixed $key): bool { - return $this->getStore()->forget($key); + return $this->getStore() + ->forget($key); } public function deleteItems(array $keys): bool @@ -117,7 +118,8 @@ public function save(CacheItemInterface $item): bool $ttl = $expires - time(); } - return $this->getStore()->put($key, $value, $ttl); + return $this->getStore() + ->put($key, $value, $ttl); } public function saveDeferred(CacheItemInterface $item): bool diff --git a/src/Configuration.php b/src/Configuration.php index 33484996..876b208f 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -12,10 +12,8 @@ final class Configuration implements \Auth0\Laravel\Contract\Configuration /** * @inheritdoc */ - public static function stringToArrayOrNull( - ?string $config, - string $delimiter = ' ' - ): ?array { + public static function stringToArrayOrNull(?string $config, string $delimiter = ' '): ?array + { if (is_string($config) && strlen($config) >= 1 && strlen($delimiter) >= 1) { $response = explode($delimiter, $config); @@ -31,10 +29,8 @@ public static function stringToArrayOrNull( /** * @inheritdoc */ - public static function stringToBoolOrNull( - ?string $config, - ?bool $default = null - ): ?bool { + public static function stringToBoolOrNull(?string $config, ?bool $default = null): ?bool + { if (is_string($config) && strlen($config) >= 1) { $config = strtolower(trim($config)); diff --git a/src/Contract/Auth/Guard.php b/src/Contract/Auth/Guard.php index 55e688fb..1b4280c3 100644 --- a/src/Contract/Auth/Guard.php +++ b/src/Contract/Auth/Guard.php @@ -8,9 +8,6 @@ interface Guard { /** * Create a new authentication guard. - * - * @param \Illuminate\Contracts\Auth\UserProvider $provider - * @param \Illuminate\Http\Request $request */ public function __construct( \Illuminate\Contracts\Auth\UserProvider $provider, @@ -19,12 +16,8 @@ public function __construct( /** * Set the current user. - * - * @param \Illuminate\Contracts\Auth\Authenticatable $user */ - public function login( - \Illuminate\Contracts\Auth\Authenticatable $user - ): self; + public function login(\Illuminate\Contracts\Auth\Authenticatable $user): self; /** * Clear the current user. diff --git a/src/Contract/Auth/User/Provider.php b/src/Contract/Auth/User/Provider.php index 0fc8a772..5f5966c8 100644 --- a/src/Contract/Auth/User/Provider.php +++ b/src/Contract/Auth/User/Provider.php @@ -11,9 +11,7 @@ interface Provider * * @param \Auth0\Laravel\Auth\User\Repository $repository A repository instance. */ - public function __construct( - \Auth0\Laravel\Auth\User\Repository $repository - ); + public function __construct(\Auth0\Laravel\Auth\User\Repository $repository); /** * Returns the assigned user provider. diff --git a/src/Contract/Auth/User/Repository.php b/src/Contract/Auth/User/Repository.php index 9997375e..9224c85a 100644 --- a/src/Contract/Auth/User/Repository.php +++ b/src/Contract/Auth/User/Repository.php @@ -11,16 +11,12 @@ interface Repository * * @param array $user An array containing the raw Auth0 user data. */ - public function fromSession( - array $user - ): ?\Illuminate\Contracts\Auth\Authenticatable; + public function fromSession(array $user): ?\Illuminate\Contracts\Auth\Authenticatable; /** * Generate a \Auth0\Laravel\Model\Stateful\User instance from a parsed Access Token. * * @param array $user An array containing the raw Auth0 user data. */ - public function fromAccessToken( - array $user - ): ?\Illuminate\Contracts\Auth\Authenticatable; + public function fromAccessToken(array $user): ?\Illuminate\Contracts\Auth\Authenticatable; } diff --git a/src/Contract/Auth0.php b/src/Contract/Auth0.php index 619958bd..0129be4d 100644 --- a/src/Contract/Auth0.php +++ b/src/Contract/Auth0.php @@ -14,9 +14,7 @@ public function getSdk(): \Auth0\SDK\Contract\Auth0Interface; /** * Create/return instance of the Auth0-PHP SDK. */ - public function setSdk( - \Auth0\SDK\Contract\Auth0Interface $sdk - ): self; + public function setSdk(\Auth0\SDK\Contract\Auth0Interface $sdk): self; /** * Create/return instance of the Auth0-PHP SdkConfiguration. @@ -26,9 +24,7 @@ public function getConfiguration(): \Auth0\SDK\Configuration\SdkConfiguration; /** * Assign the Auth0-PHP SdkConfiguration. */ - public function setConfiguration( - \Auth0\SDK\Configuration\SdkConfiguration $configuration - ): self; + public function setConfiguration(\Auth0\SDK\Configuration\SdkConfiguration $configuration): self; /** * Create/create a request state instance, a storage singleton containing authenticated user data. diff --git a/src/Contract/Configuration.php b/src/Contract/Configuration.php index 908c4c66..38954dc0 100644 --- a/src/Contract/Configuration.php +++ b/src/Contract/Configuration.php @@ -12,10 +12,7 @@ interface Configuration * @param string|null $config The string contents to convert, i.e. 'one two three'. * @param string $delimiter The string delimiter to split the string contents with; defaults to space. */ - public static function stringToArrayOrNull( - ?string $config, - string $delimiter = ' ' - ): ?array; + public static function stringToArrayOrNull(?string $config, string $delimiter = ' '): ?array; /** * Converts a truthy string representation into a boolean. @@ -23,8 +20,5 @@ public static function stringToArrayOrNull( * @param string|null $config The string contents to convert, i.e. 'true' * @param bool|null $default The default boolean value to return if a valid string wasn't provided. */ - public static function stringToBoolOrNull( - ?string $config, - ?bool $default = null - ): ?bool; + public static function stringToBoolOrNull(?string $config, ?bool $default = null): ?bool; } diff --git a/src/Contract/Event/Configuration/Built.php b/src/Contract/Event/Configuration/Built.php index eaa601a4..6809ab54 100644 --- a/src/Contract/Event/Configuration/Built.php +++ b/src/Contract/Event/Configuration/Built.php @@ -13,9 +13,7 @@ interface Built * * @param SdkConfiguration $configuration An instance of Auth0\SDK\Configuration\SdkConfiguration for use with the Auth0-PHP SDK. */ - public function __construct( - SdkConfiguration $configuration - ); + public function __construct(SdkConfiguration $configuration); /** * Returns the exception to be thrown. @@ -27,7 +25,5 @@ public function getConfiguration(): SdkConfiguration; * * @param SdkConfiguration $configuration An instance of Auth0\SDK\Configuration\SdkConfiguration for use with the Auth0-PHP SDK. */ - public function setConfiguration( - SdkConfiguration $configuration - ): self; + public function setConfiguration(SdkConfiguration $configuration): self; } diff --git a/src/Contract/Event/Stateful/AuthenticationFailed.php b/src/Contract/Event/Stateful/AuthenticationFailed.php index 858f94c3..2170fc81 100644 --- a/src/Contract/Event/Stateful/AuthenticationFailed.php +++ b/src/Contract/Event/Stateful/AuthenticationFailed.php @@ -12,19 +12,14 @@ interface AuthenticationFailed * @param \Throwable $exception An exception instance in which to throw for the authentication failure. * @param bool $throwException Whether or not $exception will be thrown. */ - public function __construct( - \Throwable $exception, - bool $throwException = true - ); + public function __construct(\Throwable $exception, bool $throwException = true); /** * Overwrite the exception to be thrown. * * @param \Throwable $exception An exception instance in which to throw for the authentication failure. */ - public function setException( - \Throwable $exception - ): self; + public function setException(\Throwable $exception): self; /** * Returns the exception to be thrown. @@ -36,9 +31,7 @@ public function getException(): \Throwable; * * @param bool $throwException Whether or not $exception will be thrown. */ - public function setThrowException( - bool $throwException - ): self; + public function setThrowException(bool $throwException): self; /** * Returns whether the provided exception will be thrown by the SDK. diff --git a/src/Contract/Event/Stateful/AuthenticationSucceeded.php b/src/Contract/Event/Stateful/AuthenticationSucceeded.php index e1c3c5b1..0fae19b0 100644 --- a/src/Contract/Event/Stateful/AuthenticationSucceeded.php +++ b/src/Contract/Event/Stateful/AuthenticationSucceeded.php @@ -11,18 +11,14 @@ interface AuthenticationSucceeded * * @param \Illuminate\Contracts\Auth\Authenticatable $user An instance of \Illuminate\Contracts\Auth\Authenticatable representing the authenticated user. */ - public function __construct( - \Illuminate\Contracts\Auth\Authenticatable $user - ); + public function __construct(\Illuminate\Contracts\Auth\Authenticatable $user); /** * Overwrite the authenticated user. * * @param \Illuminate\Contracts\Auth\Authenticatable $user An instance of \Illuminate\Contracts\Auth\Authenticatable representing the authenticated user. */ - public function setUser( - \Illuminate\Contracts\Auth\Authenticatable $user - ): self; + public function setUser(\Illuminate\Contracts\Auth\Authenticatable $user): self; /** * Return the authenticated user. diff --git a/src/Contract/Exception/Stateful/CallbackException.php b/src/Contract/Exception/Stateful/CallbackException.php index a5d8e37d..5ecd5d10 100644 --- a/src/Contract/Exception/Stateful/CallbackException.php +++ b/src/Contract/Exception/Stateful/CallbackException.php @@ -12,8 +12,5 @@ interface CallbackException * @param string $error The error message to return. * @param string $errorDescription The error description to return. */ - public static function apiException( - string $error, - string $errorDescription - ): self; + public static function apiException(string $error, string $errorDescription): self; } diff --git a/src/Contract/Http/Controller/Stateful/Callback.php b/src/Contract/Http/Controller/Stateful/Callback.php index 1adc8cc3..f16878fd 100644 --- a/src/Contract/Http/Controller/Stateful/Callback.php +++ b/src/Contract/Http/Controller/Stateful/Callback.php @@ -11,7 +11,5 @@ interface Callback * * @param \Illuminate\Http\Request $request The incoming request instance. */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse; + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse; } diff --git a/src/Contract/Http/Controller/Stateful/Login.php b/src/Contract/Http/Controller/Stateful/Login.php index c240dd94..b65839b4 100644 --- a/src/Contract/Http/Controller/Stateful/Login.php +++ b/src/Contract/Http/Controller/Stateful/Login.php @@ -12,7 +12,5 @@ interface Login * * @param \Illuminate\Http\Request $request The incoming request instance. */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse; + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse; } diff --git a/src/Contract/Http/Controller/Stateful/Logout.php b/src/Contract/Http/Controller/Stateful/Logout.php index 945fb760..e7d35442 100644 --- a/src/Contract/Http/Controller/Stateful/Logout.php +++ b/src/Contract/Http/Controller/Stateful/Logout.php @@ -12,7 +12,5 @@ interface Logout * * @param \Illuminate\Http\Request $request The incoming request instance. */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse; + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse; } diff --git a/src/Contract/Http/Middleware/Stateful/Authenticate.php b/src/Contract/Http/Middleware/Stateful/Authenticate.php index 7cd1a61f..05f6d522 100644 --- a/src/Contract/Http/Middleware/Stateful/Authenticate.php +++ b/src/Contract/Http/Middleware/Stateful/Authenticate.php @@ -9,13 +9,7 @@ interface Authenticate /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * * @return mixed */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ); + public function handle(\Illuminate\Http\Request $request, \Closure $next); } diff --git a/src/Contract/Http/Middleware/Stateful/AuthenticateOptional.php b/src/Contract/Http/Middleware/Stateful/AuthenticateOptional.php index 80a3876e..375a635f 100644 --- a/src/Contract/Http/Middleware/Stateful/AuthenticateOptional.php +++ b/src/Contract/Http/Middleware/Stateful/AuthenticateOptional.php @@ -9,13 +9,7 @@ interface AuthenticateOptional /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * * @return mixed */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ); + public function handle(\Illuminate\Http\Request $request, \Closure $next); } diff --git a/src/Contract/Http/Middleware/Stateless/Authorize.php b/src/Contract/Http/Middleware/Stateless/Authorize.php index c31e7207..e6d360cb 100644 --- a/src/Contract/Http/Middleware/Stateless/Authorize.php +++ b/src/Contract/Http/Middleware/Stateless/Authorize.php @@ -9,15 +9,7 @@ interface Authorize /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @param string $scope - * * @return mixed */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next, - string $scope - ); + public function handle(\Illuminate\Http\Request $request, \Closure $next, string $scope); } diff --git a/src/Contract/Http/Middleware/Stateless/AuthorizeOptional.php b/src/Contract/Http/Middleware/Stateless/AuthorizeOptional.php index 8615c6de..caf6bd54 100644 --- a/src/Contract/Http/Middleware/Stateless/AuthorizeOptional.php +++ b/src/Contract/Http/Middleware/Stateless/AuthorizeOptional.php @@ -9,13 +9,7 @@ interface AuthorizeOptional /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * * @return mixed */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ); + public function handle(\Illuminate\Http\Request $request, \Closure $next); } diff --git a/src/Contract/Model/User.php b/src/Contract/Model/User.php index fecdea70..2f692444 100644 --- a/src/Contract/Model/User.php +++ b/src/Contract/Model/User.php @@ -11,62 +11,40 @@ interface User * * @param array $attributes Attributes representing the user data. */ - public function __construct( - array $attributes = [] - ); + public function __construct(array $attributes = []); /** * Dynamically retrieve attributes on the model. * - * @param string $key - * * @return mixed */ - public function __get( - string $key - ); + public function __get(string $key); /** * Dynamically set attributes on the model. * - * @param string $key * @param mixed $value */ - public function __set( - string $key, - $value - ): void; + public function __set(string $key, $value): void; /** * Fill the model with an array of attributes. - * - * @param array $attributes */ - public function fill( - array $attributes - ): self; + public function fill(array $attributes): self; /** * Set a given attribute on the model. * - * @param string $key * @param mixed $value */ - public function setAttribute( - string $key, - $value - ): self; + public function setAttribute(string $key, $value): self; /** * Get an attribute from the model. * - * @param string $key * @param mixed $default * * @return mixed */ - public function getAttribute( - string $key, - $default = null - ); + public function getAttribute(string $key, $default = null); } diff --git a/src/Contract/ServiceProvider.php b/src/Contract/ServiceProvider.php index bb0d8547..2e64738f 100644 --- a/src/Contract/ServiceProvider.php +++ b/src/Contract/ServiceProvider.php @@ -9,9 +9,7 @@ interface ServiceProvider /** * Configure package details for Laravel's consumption. */ - public function configurePackage( - \Spatie\LaravelPackageTools\Package $package - ): void; + public function configurePackage(\Spatie\LaravelPackageTools\Package $package): void; /** * Register application services. diff --git a/src/Contract/StateInstance.php b/src/Contract/StateInstance.php index 5886dbfa..9ca71d92 100644 --- a/src/Contract/StateInstance.php +++ b/src/Contract/StateInstance.php @@ -21,9 +21,7 @@ public function getUser(): ?\Illuminate\Contracts\Auth\Authenticatable; * * @param \Illuminate\Contracts\Auth\Authenticatable|null $user An authenticated user context. */ - public function setUser( - ?\Illuminate\Contracts\Auth\Authenticatable $user - ): self; + public function setUser(?\Illuminate\Contracts\Auth\Authenticatable $user): self; /** * Retrieve the decoded token data for the request context, if available. @@ -33,9 +31,7 @@ public function getDecoded(): ?array; /** * Set the decoded token data for the request context. */ - public function setDecoded( - ?array $data - ): self; + public function setDecoded(?array $data): self; /** * Retrieve the id token for the request context, if available. @@ -45,9 +41,7 @@ public function getIdToken(): ?string; /** * Set the id token for the request context. */ - public function setIdToken( - ?string $idToken - ): self; + public function setIdToken(?string $idToken): self; /** * Retrieve the access token for the request context, if available. @@ -57,9 +51,7 @@ public function getAccessToken(): ?string; /** * Set the access token for the request context. */ - public function setAccessToken( - ?string $accessToken - ): self; + public function setAccessToken(?string $accessToken): self; /** * Retrieve the access token scopes for the request context, if available. @@ -69,9 +61,7 @@ public function getAccessTokenScope(): ?array; /** * Set the access token scopes for the request context. */ - public function setAccessTokenScope( - ?array $accessTokenScope - ): self; + public function setAccessTokenScope(?array $accessTokenScope): self; /** * Retrieve the access token expiration timestamp for the request context, if available. @@ -81,9 +71,7 @@ public function getAccessTokenExpiration(): ?int; /** * Set the access token expiration timestamp for the request context. */ - public function setAccessTokenExpiration( - ?int $accessTokenExpiration - ): self; + public function setAccessTokenExpiration(?int $accessTokenExpiration): self; /** * Retrieve the access token expiration state, if available. @@ -100,7 +88,5 @@ public function getRefreshToken(): ?string; * * @param string $refreshToken Refresh token returned from the code exchange. */ - public function setRefreshToken( - ?string $refreshToken - ): self; + public function setRefreshToken(?string $refreshToken): self; } diff --git a/src/Event/Configuration/Built.php b/src/Event/Configuration/Built.php index 376a14e0..1c793e62 100644 --- a/src/Event/Configuration/Built.php +++ b/src/Event/Configuration/Built.php @@ -16,18 +16,16 @@ final class Built extends \Auth0\Laravel\Event\Auth0Event implements \Auth0\Lara /** * @inheritdoc */ - public function __construct( - SdkConfiguration $configuration - ) { + public function __construct(SdkConfiguration $configuration) + { $this->configuration = $configuration; } /** * @inheritdoc */ - public function setConfiguration( - SdkConfiguration $configuration - ): self { + public function setConfiguration(SdkConfiguration $configuration): self + { $this->configuration = $configuration; return $this; } diff --git a/src/Event/Stateful/AuthenticationFailed.php b/src/Event/Stateful/AuthenticationFailed.php index d8c93f93..93c85dfa 100644 --- a/src/Event/Stateful/AuthenticationFailed.php +++ b/src/Event/Stateful/AuthenticationFailed.php @@ -19,10 +19,8 @@ final class AuthenticationFailed extends \Auth0\Laravel\Event\Auth0Event impleme /** * @inheritdoc */ - public function __construct( - \Throwable $exception, - bool $throwException = true - ) { + public function __construct(\Throwable $exception, bool $throwException = true) + { $this->exception = $exception; $this->throwException = $throwException; } @@ -30,9 +28,8 @@ public function __construct( /** * @inheritdoc */ - public function setException( - \Throwable $exception - ): self { + public function setException(\Throwable $exception): self + { $this->exception = $exception; $this->mutated = true; return $this; @@ -49,9 +46,8 @@ public function getException(): \Throwable /** * @inheritdoc */ - public function setThrowException( - bool $throwException - ): self { + public function setThrowException(bool $throwException): self + { $this->throwException = $throwException; return $this; } diff --git a/src/Event/Stateful/AuthenticationSucceeded.php b/src/Event/Stateful/AuthenticationSucceeded.php index 8cad32aa..21db6fc2 100644 --- a/src/Event/Stateful/AuthenticationSucceeded.php +++ b/src/Event/Stateful/AuthenticationSucceeded.php @@ -14,18 +14,16 @@ final class AuthenticationSucceeded extends \Auth0\Laravel\Event\Auth0Event impl /** * @inheritdoc */ - public function __construct( - \Illuminate\Contracts\Auth\Authenticatable $user - ) { + public function __construct(\Illuminate\Contracts\Auth\Authenticatable $user) + { $this->user = $user; } /** * @inheritdoc */ - public function setUser( - \Illuminate\Contracts\Auth\Authenticatable $user - ): self { + public function setUser(\Illuminate\Contracts\Auth\Authenticatable $user): self + { $this->user = $user; $this->mutated = true; return $this; diff --git a/src/Exception/Stateful/CallbackException.php b/src/Exception/Stateful/CallbackException.php index 2717a482..00d882e4 100644 --- a/src/Exception/Stateful/CallbackException.php +++ b/src/Exception/Stateful/CallbackException.php @@ -14,10 +14,8 @@ final class CallbackException extends \Exception implements \Auth0\SDK\Exception /** * @inheritdoc */ - public static function apiException( - string $error, - string $errorDescription - ): self { + public static function apiException(string $error, string $errorDescription): self + { return new self(sprintf(self::MSG_API_RESPONSE, $error, $errorDescription)); } } diff --git a/src/Http/Controller/Stateful/Callback.php b/src/Http/Controller/Stateful/Callback.php index 5c9a4af5..b942634e 100644 --- a/src/Http/Controller/Stateful/Callback.php +++ b/src/Http/Controller/Stateful/Callback.php @@ -9,9 +9,8 @@ final class Callback implements \Auth0\Laravel\Contract\Http\Controller\Stateful /** * @inheritdoc */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse { + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse + { // Check if the user already has a session: if (auth()->guard('auth0')->check()) { // They do; redirect to homepage. @@ -20,7 +19,11 @@ public function __invoke( try { if ($request->query('state') !== null && $request->query('code') !== null) { - app(\Auth0\Laravel\Auth0::class)->getSdk()->exchange(null, $request->query('code'), $request->query('state')); + app(\Auth0\Laravel\Auth0::class)->getSdk()->exchange( + null, + $request->query('code'), + $request->query('state') + ); } } catch (\Throwable $exception) { app(\Auth0\Laravel\Auth0::class)->getSdk()->clear(); @@ -59,7 +62,9 @@ public function __invoke( } // Ensure we have a valid user: - $user = auth()->guard('auth0')->user(); + $user = auth() + ->guard('auth0') + ->user(); if ($user !== null) { // Throw hookable event to allow custom application logic for successful logins: @@ -67,7 +72,9 @@ public function __invoke( event($event); // Apply any mutations to the user object: - auth()->guard('auth0')->setUser($event->getUser()); + auth() + ->guard('auth0') + ->setUser($event->getUser()); } return redirect()->intended(app()->make('config')->get('auth0.routes.home', '/')); diff --git a/src/Http/Controller/Stateful/Login.php b/src/Http/Controller/Stateful/Login.php index a73bd8dc..366d95e2 100644 --- a/src/Http/Controller/Stateful/Login.php +++ b/src/Http/Controller/Stateful/Login.php @@ -11,9 +11,8 @@ final class Login implements \Auth0\Laravel\Contract\Http\Controller\Stateful\Lo * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse { + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse + { if (auth()->guard('auth0')->check()) { return redirect()->intended(app()->make('config')->get('auth0.routes.home', '/')); } diff --git a/src/Http/Controller/Stateful/Logout.php b/src/Http/Controller/Stateful/Logout.php index 60ab5dbe..624e1552 100644 --- a/src/Http/Controller/Stateful/Logout.php +++ b/src/Http/Controller/Stateful/Logout.php @@ -9,16 +9,22 @@ final class Logout implements \Auth0\Laravel\Contract\Http\Controller\Stateful\L /** * @inheritdoc */ - public function __invoke( - \Illuminate\Http\Request $request - ): \Illuminate\Http\RedirectResponse { + public function __invoke(\Illuminate\Http\Request $request): \Illuminate\Http\RedirectResponse + { if (auth()->guard('auth0')->check()) { - auth()->guard('auth0')->logout(); + auth()->guard('auth0') + ->logout(); - $request->session()->invalidate(); - $request->session()->regenerateToken(); + $request->session() + ->invalidate(); + $request->session() + ->regenerateToken(); - return redirect()->away(app(\Auth0\Laravel\Auth0::class)->getSdk()->authentication()->getLogoutLink(url(app()->make('config')->get('auth0.routes.home', '/')))); + return redirect()->away( + app(\Auth0\Laravel\Auth0::class)->getSdk()->authentication()->getLogoutLink(url( + app()->make('config')->get('auth0.routes.home', '/') + )) + ); } return redirect()->intended(app()->make('config')->get('auth0.routes.home', '/')); diff --git a/src/Http/Middleware/Stateful/Authenticate.php b/src/Http/Middleware/Stateful/Authenticate.php index 00a4e932..aaef10a5 100644 --- a/src/Http/Middleware/Stateful/Authenticate.php +++ b/src/Http/Middleware/Stateful/Authenticate.php @@ -8,22 +8,21 @@ * This middleware will configure the authenticated user for the session using a * previously established Auth0-PHP SDK session. If a session is not available, * a redirect will be issued to a route named 'login'. - * - * @package Auth0\Laravel\Http\Middleware */ final class Authenticate implements \Auth0\Laravel\Contract\Http\Middleware\Stateful\Authenticate { /** * @inheritdoc */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ) { - $user = auth()->guard('auth0')->user(); + public function handle(\Illuminate\Http\Request $request, \Closure $next) + { + $user = auth() + ->guard('auth0') + ->user(); if ($user !== null && $user instanceof \Auth0\Laravel\Contract\Model\Stateful\User) { - auth()->guard('auth0')->login($user); + auth()->guard('auth0') + ->login($user); return $next($request); } diff --git a/src/Http/Middleware/Stateful/AuthenticateOptional.php b/src/Http/Middleware/Stateful/AuthenticateOptional.php index d7e93ae0..cdecea66 100644 --- a/src/Http/Middleware/Stateful/AuthenticateOptional.php +++ b/src/Http/Middleware/Stateful/AuthenticateOptional.php @@ -8,22 +8,21 @@ * This middleware will configure the authenticated user for the session using a * previously established Auth0-PHP SDK session. If a session is not available, * the authenticated user will be set as null. - * - * @package Auth0\Laravel\Http\Middleware */ final class AuthenticateOptional implements \Auth0\Laravel\Contract\Http\Middleware\Stateful\AuthenticateOptional { /** * @inheritdoc */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ) { - $user = auth()->guard('auth0')->user(); + public function handle(\Illuminate\Http\Request $request, \Closure $next) + { + $user = auth() + ->guard('auth0') + ->user(); if ($user !== null && $user instanceof \Auth0\Laravel\Contract\Model\Stateful\User) { - auth()->guard('auth0')->login($user); + auth()->guard('auth0') + ->login($user); } return $next($request); diff --git a/src/Http/Middleware/Stateless/Authorize.php b/src/Http/Middleware/Stateless/Authorize.php index eca524d9..5a3102ba 100644 --- a/src/Http/Middleware/Stateless/Authorize.php +++ b/src/Http/Middleware/Stateless/Authorize.php @@ -7,27 +7,25 @@ /** * This middleware will configure the authenticated user using an available access token. * If a token is not available, it will raise an exception. - * - * @package Auth0\Laravel\Http\Middleware */ final class Authorize implements \Auth0\Laravel\Contract\Http\Middleware\Stateless\Authorize { /** * @inheritdoc */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next, - string $scope = '' - ) { - $user = auth()->guard('auth0')->user(); + public function handle(\Illuminate\Http\Request $request, \Closure $next, string $scope = '') + { + $user = auth() + ->guard('auth0') + ->user(); if ($user !== null && $user instanceof \Auth0\Laravel\Contract\Model\Stateless\User) { if (strlen($scope) >= 1 && auth()->guard('auth0')->hasScope($scope) === false) { return abort(403, 'Unauthorized'); } - auth()->login($user); + auth() + ->login($user); return $next($request); } diff --git a/src/Http/Middleware/Stateless/AuthorizeOptional.php b/src/Http/Middleware/Stateless/AuthorizeOptional.php index 1ae72a50..43921c71 100644 --- a/src/Http/Middleware/Stateless/AuthorizeOptional.php +++ b/src/Http/Middleware/Stateless/AuthorizeOptional.php @@ -6,22 +6,21 @@ /** * This middleware will configure the authenticated user using an available access token. - * - * @package Auth0\Laravel\Http\Middleware */ final class AuthorizeOptional implements \Auth0\Laravel\Contract\Http\Middleware\Stateless\AuthorizeOptional { /** * @inheritdoc */ - public function handle( - \Illuminate\Http\Request $request, - \Closure $next - ) { - $user = auth()->guard('auth0')->user(); + public function handle(\Illuminate\Http\Request $request, \Closure $next) + { + $user = auth() + ->guard('auth0') + ->user(); if ($user !== null && $user instanceof \Auth0\Laravel\Contract\Model\Stateless\User) { - auth()->guard('auth0')->login($user); + auth()->guard('auth0') + ->login($user); } return $next($request); diff --git a/src/Model/User.php b/src/Model/User.php index 7e186a3e..afc9fea4 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -14,37 +14,32 @@ abstract class User implements \Illuminate\Contracts\Auth\Authenticatable, \Auth /** * @inheritdoc */ - public function __construct( - array $attributes = [] - ) { + public function __construct(array $attributes = []) + { $this->fill($attributes); } /** * @inheritdoc */ - public function __get( - string $key - ) { + public function __get(string $key) + { return $this->getAttribute($key); } /** * @inheritdoc */ - public function __set( - string $key, - $value - ): void { + public function __set(string $key, $value): void + { $this->setAttribute($key, $value); } /** * @inheritdoc */ - public function fill( - array $attributes - ): self { + public function fill(array $attributes): self + { foreach ($attributes as $key => $value) { $this->setAttribute($key, $value); } @@ -55,10 +50,8 @@ public function fill( /** * @inheritdoc */ - public function setAttribute( - string $key, - $value - ): self { + public function setAttribute(string $key, $value): self + { $this->attributes[$key] = $value; return $this; } @@ -66,10 +59,8 @@ public function setAttribute( /** * @inheritdoc */ - public function getAttribute( - string $key, - $default = null - ) { + public function getAttribute(string $key, $default = null) + { return $this->attributes[$key] ?? $default; } @@ -110,9 +101,8 @@ public function getRememberToken(): string * * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter */ - public function setRememberToken( - $value - ): void { + public function setRememberToken($value): void + { } /** diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 80759109..fa65d7ec 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -9,9 +9,8 @@ final class ServiceProvider extends \Spatie\LaravelPackageTools\PackageServicePr /** * @inheritdoc */ - public function configurePackage( - \Spatie\LaravelPackageTools\Package $package - ): void { + public function configurePackage(\Spatie\LaravelPackageTools\Package $package): void + { $package ->name('auth0') ->hasConfigFile(); @@ -24,11 +23,17 @@ public function registeringPackage(): void { app()->singleton(Auth0::class, static fn (): \Auth0\Laravel\Auth0 => new Auth0()); - app()->singleton('auth0', static fn (): \Auth0\Laravel\Auth0 => app()->make(Auth0::class)); + app() + ->singleton('auth0', static fn (): \Auth0\Laravel\Auth0 => app()->make(Auth0::class)); - app()->singleton(StateInstance::class, static fn (): \Auth0\Laravel\StateInstance => new StateInstance()); + app() + ->singleton(StateInstance::class, static fn (): \Auth0\Laravel\StateInstance => new StateInstance()); - app()->singleton(\Auth0\Laravel\Auth\User\Repository::class, static fn (): \Auth0\Laravel\Auth\User\Repository => new \Auth0\Laravel\Auth\User\Repository()); + app() + ->singleton( + \Auth0\Laravel\Auth\User\Repository::class, + static fn (): \Auth0\Laravel\Auth\User\Repository => new \Auth0\Laravel\Auth\User\Repository() + ); } /** @@ -36,14 +41,39 @@ public function registeringPackage(): void */ public function bootingPackage(): void { - auth()->provider('auth0', static fn ($app, array $config): \Auth0\Laravel\Auth\User\Provider => new \Auth0\Laravel\Auth\User\Provider(app()->make($config['repository']))); + auth()->provider( + 'auth0', + static fn ($app, array $config): \Auth0\Laravel\Auth\User\Provider => new \Auth0\Laravel\Auth\User\Provider( + app()->make( + $config['repository'] + ) + ) + ); - auth()->extend('auth0', static fn ($app, $name, array $config): \Auth0\Laravel\Auth\Guard => new \Auth0\Laravel\Auth\Guard(auth()->createUserProvider($config['provider']), $app->make('request'))); + auth() + ->extend( + 'auth0', + static fn ($app, $name, array $config): \Auth0\Laravel\Auth\Guard => new \Auth0\Laravel\Auth\Guard( + auth()->createUserProvider( + $config['provider'] + ), + $app->make( + 'request' + ) + ) + ); - $router = app()->make(\Illuminate\Routing\Router::class); + $router = app() + ->make(\Illuminate\Routing\Router::class); $router->aliasMiddleware('auth0.authenticate', \Auth0\Laravel\Http\Middleware\Stateful\Authenticate::class); - $router->aliasMiddleware('auth0.authenticate.optional', \Auth0\Laravel\Http\Middleware\Stateful\AuthenticateOptional::class); + $router->aliasMiddleware( + 'auth0.authenticate.optional', + \Auth0\Laravel\Http\Middleware\Stateful\AuthenticateOptional::class + ); $router->aliasMiddleware('auth0.authorize', \Auth0\Laravel\Http\Middleware\Stateless\Authorize::class); - $router->aliasMiddleware('auth0.authorize.optional', \Auth0\Laravel\Http\Middleware\Stateless\AuthorizeOptional::class); + $router->aliasMiddleware( + 'auth0.authorize.optional', + \Auth0\Laravel\Http\Middleware\Stateless\AuthorizeOptional::class + ); } } diff --git a/src/StateInstance.php b/src/StateInstance.php index 3adfab89..6eb6614a 100644 --- a/src/StateInstance.php +++ b/src/StateInstance.php @@ -67,9 +67,8 @@ public function getUser(): ?\Illuminate\Contracts\Auth\Authenticatable /** * @inheritdoc */ - public function setUser( - ?\Illuminate\Contracts\Auth\Authenticatable $user - ): self { + public function setUser(?\Illuminate\Contracts\Auth\Authenticatable $user): self + { $this->user = $user; return $this; } @@ -85,9 +84,8 @@ public function getDecoded(): ?array /** * @inheritdoc */ - public function setDecoded( - ?array $data - ): self { + public function setDecoded(?array $data): self + { $this->decoded = $data; return $this; } @@ -103,9 +101,8 @@ public function getIdToken(): ?string /** * @inheritdoc */ - public function setIdToken( - ?string $idToken - ): self { + public function setIdToken(?string $idToken): self + { $this->idToken = $idToken; return $this; } @@ -121,9 +118,8 @@ public function getAccessToken(): ?string /** * @inheritdoc */ - public function setAccessToken( - ?string $accessToken - ): self { + public function setAccessToken(?string $accessToken): self + { $this->accessToken = $accessToken; return $this; } @@ -139,9 +135,8 @@ public function getAccessTokenScope(): ?array /** * @inheritdoc */ - public function setAccessTokenScope( - ?array $accessTokenScope - ): self { + public function setAccessTokenScope(?array $accessTokenScope): self + { $this->accessTokenScope = $accessTokenScope; return $this; } @@ -157,9 +152,8 @@ public function getAccessTokenExpiration(): ?int /** * @inheritdoc */ - public function setAccessTokenExpiration( - ?int $accessTokenExpiration - ): self { + public function setAccessTokenExpiration(?int $accessTokenExpiration): self + { $this->accessTokenExpiration = $accessTokenExpiration; return $this; } @@ -189,9 +183,8 @@ public function getRefreshToken(): ?string /** * @inheritdoc */ - public function setRefreshToken( - ?string $refreshToken - ): self { + public function setRefreshToken(?string $refreshToken): self + { $this->refreshToken = $refreshToken; return $this; } diff --git a/src/Store/LaravelSession.php b/src/Store/LaravelSession.php index 3ca4e98f..40d06ea3 100644 --- a/src/Store/LaravelSession.php +++ b/src/Store/LaravelSession.php @@ -36,10 +36,8 @@ final class LaravelSession implements StoreInterface * @param SdkConfiguration $configuration Base configuration options for the SDK. See the SdkConfiguration class constructor for options. * @param string $sessionPrefix A string to prefix session keys with. */ - public function __construct( - SdkConfiguration $configuration, - string $sessionPrefix = 'auth0' - ) { + public function __construct(SdkConfiguration $configuration, string $sessionPrefix = 'auth0') + { $this->configuration = $configuration; $this->sessionPrefix = $sessionPrefix; } @@ -49,9 +47,8 @@ public function __construct( * * @param bool $deferring Whether to defer persisting the storage state. */ - public function defer( - bool $deferring - ): void { + public function defer(bool $deferring): void + { return; } @@ -61,12 +58,11 @@ public function defer( * @param string $key Session key to set. * @param mixed $value Value to use. */ - public function set( - string $key, - $value - ): void { + public function set(string $key, $value): void + { $this->boot(); - $this->getStore()->put($this->getPrefixedKey($key), $value); + $this->getStore() + ->put($this->getPrefixedKey($key), $value); } /** @@ -77,12 +73,11 @@ public function set( * * @return mixed */ - public function get( - string $key, - $default = null - ) { + public function get(string $key, $default = null) + { $this->boot(); - return $this->getStore()->get($this->getPrefixedKey($key), $default); + return $this->getStore() + ->get($this->getPrefixedKey($key), $default); } /** @@ -95,7 +90,8 @@ public function purge(): void // It would be unwise for us to simply flush() a session here, as it is shared with the app ecosystem. // Instead, iterate through the session data, and if they key is prefixed with our assigned string, delete it. - $pairs = $this->getStore()->all(); + $pairs = $this->getStore() + ->all(); $prefix = $this->sessionPrefix . '_'; foreach (array_keys($pairs) as $key) { @@ -110,11 +106,11 @@ public function purge(): void * * @param string $key Session key to delete. */ - public function delete( - string $key - ): void { + public function delete(string $key): void + { $this->boot(); - $this->getStore()->forget($this->getPrefixedKey($key)); + $this->getStore() + ->forget($this->getPrefixedKey($key)); } /** @@ -123,8 +119,9 @@ public function delete( private function boot(): void { if (! $this->booted) { - if (!$this->getStore()->isStarted()) { - $this->getStore()->start(); + if (! $this->getStore()->isStarted()) { + $this->getStore() + ->start(); } $this->booted = true; @@ -141,7 +138,7 @@ private function getStore(): \Illuminate\Session\Store return $request->session(); } - throw new Exception("A cache must be configured."); + throw new Exception('A cache must be configured.'); } private function getPrefixedKey(string $key): string diff --git a/src/Traits/ActingAsAuth0User.php b/src/Traits/ActingAsAuth0User.php index 120f0b50..c77b5129 100644 --- a/src/Traits/ActingAsAuth0User.php +++ b/src/Traits/ActingAsAuth0User.php @@ -10,22 +10,16 @@ trait ActingAsAuth0User { - abstract public function actingAs( - UserContract $user, - $guard = null - ); + abstract public function actingAs(UserContract $user, $guard = null); /** * use this method to impersonate a specific auth0 user * if you pass an attributes array, it will be merged with a set of default values * - * @param array $attributes - * * @return mixed */ - public function actingAsAuth0User( - array $attributes = [] - ) { + public function actingAsAuth0User(array $attributes = []) + { $defaults = [ 'sub' => 'some-auth0-user-id', 'azp' => 'some-auth0-appplication-client-id',