From 28ebcc9a332e40ffa9e375ee26d46ae387d13ea9 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 03:13:21 +0330 Subject: [PATCH 1/3] [13.x] Use unique ids on client model --- database/factories/ClientFactory.php | 21 ++---------------- src/Client.php | 33 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 5089b748..b34a6c0e 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -28,7 +28,7 @@ public function modelName() */ public function definition() { - return $this->ensurePrimaryKeyIsSet([ + return [ 'user_id' => null, 'name' => $this->faker->company(), 'secret' => Str::random(40), @@ -36,24 +36,7 @@ public function definition() 'personal_access_client' => false, 'password_client' => false, 'revoked' => false, - ]); - } - - /** - * Ensure the primary key is set on the model when using UUIDs. - * - * @param array $data - * @return array - */ - protected function ensurePrimaryKeyIsSet(array $data) - { - if (Passport::clientUuids()) { - $keyName = (new ($this->modelName()))->getKeyName(); - - $data[$keyName] = (string) Str::orderedUuid(); - } - - return $data; + ]; } /** diff --git a/src/Client.php b/src/Client.php index 4fc50933..4fab051f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,19 +59,16 @@ class Client extends Model public $plainSecret; /** - * Bootstrap the model and its traits. + * Create a new Eloquent model instance. * + * @param array $attributes * @return void */ - public static function boot() + public function __construct(array $attributes = []) { - parent::boot(); + parent::__construct($attributes); - static::creating(function ($model) { - if (Passport::clientUuids()) { - $model->{$model->getKeyName()} = $model->{$model->getKeyName()} ?: (string) Str::orderedUuid(); - } - }); + $this->usesUniqueIds = Passport::clientUuids(); } /** @@ -203,6 +200,26 @@ public function confidential() return ! empty($this->secret); } + /** + * Get the columns that should receive a unique identifier. + * + * @return array + */ + public function uniqueIds() + { + return Passport::clientUuids() ? [$this->getKeyName()] : []; + } + + /** + * Generate a new key for the model. + * + * @return string + */ + public function newUniqueId() + { + return Passport::clientUuids() ? (string) Str::orderedUuid() : null; + } + /** * Get the auto-incrementing key type. * From 26b8aa13ae30319dffa9bb64ee7fa309cdbc577b Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 04:04:20 +0330 Subject: [PATCH 2/3] drop support for Laravel 9.x --- .github/workflows/tests.yml | 4 +--- UPGRADE.md | 6 ++++++ composer.json | 18 +++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6292d460..e83e9999 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,12 +17,10 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2, 8.3] - laravel: [9, 10, 11] + laravel: [10, 11] exclude: - php: 8.1 laravel: 11 - - php: 8.3 - laravel: 9 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/UPGRADE.md b/UPGRADE.md index 79c7817b..e1a60011 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -10,6 +10,12 @@ PR: https://github.com/laravel/passport/pull/1734 PHP 8.1 is now the minimum required version. +### Minimum Laravel Version + +PR: https://github.com/laravel/passport/pull/1757 + +Laravel 10.0 is now the minimum required version. + ### OAuth2 Server PR: https://github.com/laravel/passport/pull/1734 diff --git a/composer.json b/composer.json index e8dad678..df414d41 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ "ext-json": "*", "ext-openssl": "*", "firebase/php-jwt": "^6.4", - "illuminate/auth": "^9.21|^10.0|^11.0", - "illuminate/console": "^9.21|^10.0|^11.0", - "illuminate/container": "^9.21|^10.0|^11.0", - "illuminate/contracts": "^9.21|^10.0|^11.0", - "illuminate/cookie": "^9.21|^10.0|^11.0", - "illuminate/database": "^9.21|^10.0|^11.0", - "illuminate/encryption": "^9.21|^10.0|^11.0", - "illuminate/http": "^9.21|^10.0|^11.0", - "illuminate/support": "^9.21|^10.0|^11.0", + "illuminate/auth": "^^10.0|^11.0", + "illuminate/console": "^10.0|^11.0", + "illuminate/container": "^10.0|^11.0", + "illuminate/contracts": "^10.0|^11.0", + "illuminate/cookie": "^10.0|^11.0", + "illuminate/database": "^10.0|^11.0", + "illuminate/encryption": "^10.0|^11.0", + "illuminate/http": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", "lcobucci/jwt": "^5.0", "league/oauth2-server": "^9.0", "nyholm/psr7": "^1.5", From 0f7dc2dd2d170b86f56d97007abe89dfd4f47a98 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 04:09:22 +0330 Subject: [PATCH 3/3] wip --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index df414d41..b806d86a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-json": "*", "ext-openssl": "*", "firebase/php-jwt": "^6.4", - "illuminate/auth": "^^10.0|^11.0", + "illuminate/auth": "^10.0|^11.0", "illuminate/console": "^10.0|^11.0", "illuminate/container": "^10.0|^11.0", "illuminate/contracts": "^10.0|^11.0",