From 0c594058e9b65769456a19c3a74a383b350a82cb Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 16 Mar 2024 15:26:12 +0800 Subject: [PATCH 1/7] add user destroyed/disabled/enabled event --- app/Console/Commands/FireEvent.php | 8 ++++- app/Events/UserDestroyed.php | 38 ++++++++++++++++++++++ app/Events/UserDisabled.php | 38 ++++++++++++++++++++++ app/Events/UserEnabled.php | 38 ++++++++++++++++++++++ app/Http/Middleware/BootNexus.php | 8 ++--- app/Listeners/RemoveOauthTokens.php | 44 ++++++++++++++++++++++++++ app/Providers/EventServiceProvider.php | 9 ++++++ app/Repositories/UserRepository.php | 3 ++ include/globalfunctions.php | 5 +++ 9 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 app/Events/UserDestroyed.php create mode 100644 app/Events/UserDisabled.php create mode 100644 app/Events/UserEnabled.php create mode 100644 app/Listeners/RemoveOauthTokens.php diff --git a/app/Console/Commands/FireEvent.php b/app/Console/Commands/FireEvent.php index 96c1c864..4d58284a 100644 --- a/app/Console/Commands/FireEvent.php +++ b/app/Console/Commands/FireEvent.php @@ -3,6 +3,9 @@ namespace App\Console\Commands; use App\Events\TorrentCreated; +use App\Events\UserDestroyed; +use App\Events\UserDisabled; +use App\Events\UserEnabled; use Illuminate\Console\Command; class FireEvent extends Command @@ -22,7 +25,10 @@ class FireEvent extends Command protected $description = 'Fire a event, options: --name, --id'; protected array $eventMaps = [ - "torrent_created" => TorrentCreated::class + "torrent_created" => TorrentCreated::class, + "user_destroyed" => UserDestroyed::class, + "user_disabled" => UserDisabled::class, + "user_enabled" => UserEnabled::class, ]; /** diff --git a/app/Events/UserDestroyed.php b/app/Events/UserDestroyed.php new file mode 100644 index 00000000..84756866 --- /dev/null +++ b/app/Events/UserDestroyed.php @@ -0,0 +1,38 @@ +id = $id; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/UserDisabled.php b/app/Events/UserDisabled.php new file mode 100644 index 00000000..6d388141 --- /dev/null +++ b/app/Events/UserDisabled.php @@ -0,0 +1,38 @@ +id = $id; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/UserEnabled.php b/app/Events/UserEnabled.php new file mode 100644 index 00000000..31de6df6 --- /dev/null +++ b/app/Events/UserEnabled.php @@ -0,0 +1,38 @@ +id = $id; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Http/Middleware/BootNexus.php b/app/Http/Middleware/BootNexus.php index 80e79fa2..42710b07 100644 --- a/app/Http/Middleware/BootNexus.php +++ b/app/Http/Middleware/BootNexus.php @@ -18,10 +18,10 @@ class BootNexus public function handle(Request $request, Closure $next) { Nexus::boot(); - do_log(sprintf( - "Nexus booted. request.server: %s, request.header: %s, request.query: %s, request.input: %s", - nexus_json_encode($request->server()), nexus_json_encode($request->header()), nexus_json_encode($request->query()), nexus_json_encode($request->input()) - )); +// do_log(sprintf( +// "Nexus booted. request.server: %s, request.header: %s, request.query: %s, request.input: %s", +// nexus_json_encode($request->server()), nexus_json_encode($request->header()), nexus_json_encode($request->query()), nexus_json_encode($request->input()) +// )); return $next($request); } diff --git a/app/Listeners/RemoveOauthTokens.php b/app/Listeners/RemoveOauthTokens.php new file mode 100644 index 00000000..d1d82de9 --- /dev/null +++ b/app/Listeners/RemoveOauthTokens.php @@ -0,0 +1,44 @@ +id; + $modelNames = [ + Passport::$authCodeModel, + Passport::$tokenModel, + ]; + foreach ($modelNames as $name) { + /** + * @var $model Model + */ + $model = new $name(); + $model::query()->where("user_id", $uid)->forceDelete(); + } + do_log(sprintf("success remove user: %d oauth tokens related.", $uid)); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 996ba5a9..c8df45a3 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -5,7 +5,10 @@ namespace App\Providers; use App\Events\SeedBoxRecordUpdated; use App\Events\TorrentCreated; use App\Events\TorrentUpdated; +use App\Events\UserDestroyed; +use App\Events\UserDisabled; use App\Listeners\FetchTorrentImdb; +use App\Listeners\RemoveOauthTokens; use App\Listeners\RemoveSeedBoxRecordCache; use App\Listeners\SyncTorrentToEs; use Illuminate\Auth\Events\Registered; @@ -33,6 +36,12 @@ class EventServiceProvider extends ServiceProvider TorrentCreated::class => [ FetchTorrentImdb::class, ], + UserDestroyed::class => [ + RemoveOauthTokens::class, + ], + UserDisabled::class => [ + RemoveOauthTokens::class, + ], ]; /** diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 791a4d17..7071ebbf 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -198,6 +198,7 @@ class UserRepository extends BaseRepository }); do_log("user: $uid, $modCommentText"); $this->clearCache($targetUser); + fire_event("user_disabled", $uid); return true; } @@ -224,6 +225,7 @@ class UserRepository extends BaseRepository $targetUser->updateWithModComment($update, $modCommentText); do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update)); $this->clearCache($targetUser); + fire_event("user_enabled", $uid); return true; } @@ -654,6 +656,7 @@ class UserRepository extends BaseRepository } UserBanLog::query()->insert($userBanLogs); do_action("user_delete", $id); + fire_event("user_destroyed", $id); return true; } diff --git a/include/globalfunctions.php b/include/globalfunctions.php index cf994879..6f8b8b07 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1226,3 +1226,8 @@ function get_snatch_info($torrentId, $userId) { return mysql_fetch_assoc(sql_query(sprintf('select * from snatched where torrentid = %s and userid = %s order by id desc limit 1', $torrentId, $userId))); } + +function fire_event(string $name, int $id): void +{ + executeCommand("event:fire --name=$name --id=$id", "string", true, false); +} From 98088d8cf0b4c0fb24a8b57fd1e05aa4c3c7a341 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 16 Mar 2024 15:26:53 +0800 Subject: [PATCH 2/7] update release date --- include/constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants.php b/include/constants.php index 0ddfaa4e..dc204c74 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ Date: Sat, 16 Mar 2024 22:12:54 +0800 Subject: [PATCH 3/7] fix https detect --- nexus/Nexus.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/nexus/Nexus.php b/nexus/Nexus.php index e8a4ce6e..9755bc7b 100644 --- a/nexus/Nexus.php +++ b/nexus/Nexus.php @@ -100,6 +100,14 @@ final class Nexus $this->logSequence++; } + private function getFirst(string $result): string + { + if (str_contains($result, ",")) { + return strstr($result, ",", true); + } + return $result; + } + public function getRequestSchema() { $schema = $this->retrieveFromServer(['HTTP_X_FORWARDED_PROTO', 'REQUEST_SCHEME', 'HTTP_SCHEME']); @@ -109,18 +117,19 @@ final class Nexus $schema = 'https'; } } - return $schema; + return $this->getFirst($schema); } public function getRequestHost(): string { - $host = $this->retrieveFromServer(['HTTP_HOST', 'host', ], true); - return (string)$host; + $host = $this->retrieveFromServer(['HTTP_HOST', 'host', 'HTTP_X_FORWARDED_HOST'], true); + return $this->getFirst(strval($host)); } - public function getRequestIp() + public function getRequestIp(): string { - return $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'x-forwarded-for', 'HTTP_REMOTE_ADDR', 'REMOTE_ADDR'], true); + $ip = $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'x-forwarded-for', 'HTTP_REMOTE_ADDR', 'REMOTE_ADDR'], true); + return $this->getFirst($ip); } private function retrieveFromServer(array $fields, bool $includeHeader = false) @@ -134,12 +143,6 @@ final class Nexus } foreach ($fields as $field) { $result = $servers[$field] ?? null; - if ($result && in_array($field, ['HTTP_X_FORWARDED_FOR', 'x-forwarded-for'])) { - $result = preg_split('/[,\s]+/', $result); - } - if (is_array($result)) { - $result = Arr::first($result); - } if ($result !== null && $result !== '') { return $result; } From f30f1da20150fbe577b8f3a74e779ec7b84c97c6 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 16 Mar 2024 22:17:31 +0800 Subject: [PATCH 4/7] HTTP_X_FORWARDED_PROTO first --- nexus/Nexus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nexus/Nexus.php b/nexus/Nexus.php index 9755bc7b..b78d7390 100644 --- a/nexus/Nexus.php +++ b/nexus/Nexus.php @@ -95,7 +95,7 @@ final class Nexus return $this->script == 'announce'; } - public function incrementLogSequence() + public function incrementLogSequence(): void { $this->logSequence++; } @@ -108,7 +108,7 @@ final class Nexus return $result; } - public function getRequestSchema() + public function getRequestSchema(): string { $schema = $this->retrieveFromServer(['HTTP_X_FORWARDED_PROTO', 'REQUEST_SCHEME', 'HTTP_SCHEME']); if (empty($schema)) { @@ -122,7 +122,7 @@ final class Nexus public function getRequestHost(): string { - $host = $this->retrieveFromServer(['HTTP_HOST', 'host', 'HTTP_X_FORWARDED_HOST'], true); + $host = $this->retrieveFromServer(['HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'host'], true); return $this->getFirst(strval($host)); } From 5ac5e8342dd868df2f546790335def7f0f2604c0 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 16 Mar 2024 23:16:48 +0800 Subject: [PATCH 5/7] add oauth zh_TW translatioin --- resources/lang/zh_TW/oauth.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/lang/zh_TW/oauth.php b/resources/lang/zh_TW/oauth.php index 38e424a8..819e1214 100644 --- a/resources/lang/zh_TW/oauth.php +++ b/resources/lang/zh_TW/oauth.php @@ -6,4 +6,8 @@ return [ 'revoked' => '有效', 'access_token' => '訪問令牌', 'refresh_token' => '刷新令牌', + 'authorization_request_title' => '授權請求', + 'authorization_request_desc' => '正在請求獲取您賬號的訪問權限', + 'btn_approve' => '授權', + 'btn_deny' => '取消', ]; From 3e96d18b48ac9d5be1ae7d48d2ad5d55021a0923 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 17 Mar 2024 02:39:26 +0800 Subject: [PATCH 6/7] oauth support skips authorization --- .../Resources/Oauth/ClientResource.php | 12 +++++++ app/Models/OauthClient.php | 13 +++++++ app/Providers/AppServiceProvider.php | 2 ++ app/Providers/AuthServiceProvider.php | 3 ++ ...1_000001_create_oauth_auth_codes_table.php | 31 ++++++++++++++++ ...00002_create_oauth_access_tokens_table.php | 33 +++++++++++++++++ ...0003_create_oauth_refresh_tokens_table.php | 29 +++++++++++++++ ...6_01_000004_create_oauth_clients_table.php | 35 +++++++++++++++++++ ...te_oauth_personal_access_clients_table.php | 28 +++++++++++++++ ...orization_field_to_oauth_clients_table.php | 32 +++++++++++++++++ include/constants.php | 2 +- resources/lang/en/oauth.php | 1 + resources/lang/zh_CN/oauth.php | 1 + resources/lang/zh_TW/oauth.php | 1 + 14 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 app/Models/OauthClient.php create mode 100644 database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php create mode 100644 database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php create mode 100644 database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php create mode 100644 database/migrations/2016_06_01_000004_create_oauth_clients_table.php create mode 100644 database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php create mode 100644 database/migrations/2024_03_17_021209_add_skips_authorization_field_to_oauth_clients_table.php diff --git a/app/Filament/Resources/Oauth/ClientResource.php b/app/Filament/Resources/Oauth/ClientResource.php index d9ae21ed..6c4c47dd 100644 --- a/app/Filament/Resources/Oauth/ClientResource.php +++ b/app/Filament/Resources/Oauth/ClientResource.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources\Oauth; +use App\Filament\OptionsTrait; use App\Filament\PageListSingle; use App\Filament\Resources\Oauth\ClientResource\Pages; use App\Filament\Resources\Oauth\ClientResource\RelationManagers; @@ -16,6 +17,8 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class ClientResource extends Resource { + use OptionsTrait; + protected static ?string $model = Client::class; protected static ?string $navigationIcon = 'heroicon-o-collection'; @@ -40,6 +43,11 @@ class ClientResource extends Resource ->schema([ Forms\Components\TextInput::make('name')->label(__('label.name')), Forms\Components\TextInput::make('redirect')->label(__('oauth.redirect')), + Forms\Components\Radio::make('skips_authorization') + ->options(self::getYesNoOptions()) + ->inline() + ->default(0) + ->label(__('oauth.skips_authorization')), ]); } @@ -52,6 +60,10 @@ class ClientResource extends Resource Tables\Columns\TextColumn::make('name')->label(__('label.name')), Tables\Columns\TextColumn::make('secret')->label(__('oauth.secret')), Tables\Columns\TextColumn::make('redirect')->label(__('oauth.redirect')), + Tables\Columns\IconColumn::make('skips_authorization') + ->boolean() + ->label(__('oauth.skips_authorization')) + , ]) ->filters([ diff --git a/app/Models/OauthClient.php b/app/Models/OauthClient.php new file mode 100644 index 00000000..6c9de2f7 --- /dev/null +++ b/app/Models/OauthClient.php @@ -0,0 +1,13 @@ +skips_authorization; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 08035ded..ec3dbb35 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; use Illuminate\Http\Resources\Json\JsonResource; +use Laravel\Passport\Passport; use Nexus\Nexus; use Filament\Facades\Filament; use NexusPlugin\Menu\Filament\MenuItemResource; @@ -22,6 +23,7 @@ class AppServiceProvider extends ServiceProvider */ public function register() { + Passport::ignoreMigrations(); do_action('nexus_register'); } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 3b9be3ca..063c8b5e 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -9,6 +9,7 @@ use App\Models\Category; use App\Models\Codec; use App\Models\Icon; use App\Models\Media; +use App\Models\OauthClient; use App\Models\Plugin; use App\Models\Processing; use App\Models\SearchBox; @@ -21,6 +22,7 @@ use App\Policies\CodecPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Laravel\Passport\Passport; class AuthServiceProvider extends ServiceProvider { @@ -54,6 +56,7 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); + Passport::useClientModel(OauthClient::class); Auth::viaRequest('nexus-cookie', function (Request $request) { return $this->getUserByCookie($request->cookie()); diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php new file mode 100644 index 00000000..7b93b406 --- /dev/null +++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -0,0 +1,31 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->index(); + $table->unsignedBigInteger('client_id'); + $table->text('scopes')->nullable(); + $table->boolean('revoked'); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_auth_codes'); + } +}; diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php new file mode 100644 index 00000000..598798ee --- /dev/null +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -0,0 +1,33 @@ +string('id', 100)->primary(); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->unsignedBigInteger('client_id'); + $table->string('name')->nullable(); + $table->text('scopes')->nullable(); + $table->boolean('revoked'); + $table->timestamps(); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_access_tokens'); + } +}; diff --git a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php new file mode 100644 index 00000000..b007904c --- /dev/null +++ b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php @@ -0,0 +1,29 @@ +string('id', 100)->primary(); + $table->string('access_token_id', 100)->index(); + $table->boolean('revoked'); + $table->dateTime('expires_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_refresh_tokens'); + } +}; diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php new file mode 100644 index 00000000..776ccfab --- /dev/null +++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->string('name'); + $table->string('secret', 100)->nullable(); + $table->string('provider')->nullable(); + $table->text('redirect'); + $table->boolean('personal_access_client'); + $table->boolean('password_client'); + $table->boolean('revoked'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_clients'); + } +}; diff --git a/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php new file mode 100644 index 00000000..7c9d1e8f --- /dev/null +++ b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php @@ -0,0 +1,28 @@ +bigIncrements('id'); + $table->unsignedBigInteger('client_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('oauth_personal_access_clients'); + } +}; diff --git a/database/migrations/2024_03_17_021209_add_skips_authorization_field_to_oauth_clients_table.php b/database/migrations/2024_03_17_021209_add_skips_authorization_field_to_oauth_clients_table.php new file mode 100644 index 00000000..8b4daed5 --- /dev/null +++ b/database/migrations/2024_03_17_021209_add_skips_authorization_field_to_oauth_clients_table.php @@ -0,0 +1,32 @@ +boolean("skips_authorization")->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('oauth_clients', function (Blueprint $table) { + $table->dropColumn("skips_authorization"); + }); + } +}; diff --git a/include/constants.php b/include/constants.php index dc204c74..bfece3db 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 'is requesting permission to access your account', 'btn_approve' => 'Authorize', 'btn_deny' => 'Cancel', + 'skips_authorization' => 'Skips authorization', ]; diff --git a/resources/lang/zh_CN/oauth.php b/resources/lang/zh_CN/oauth.php index 1fa85781..ad647b60 100644 --- a/resources/lang/zh_CN/oauth.php +++ b/resources/lang/zh_CN/oauth.php @@ -10,4 +10,5 @@ return [ 'authorization_request_desc' => '正在请求获取您账号的访问权限', 'btn_approve' => '授权', 'btn_deny' => '取消', + 'skips_authorization' => '跳过授权', ]; diff --git a/resources/lang/zh_TW/oauth.php b/resources/lang/zh_TW/oauth.php index 819e1214..c7217224 100644 --- a/resources/lang/zh_TW/oauth.php +++ b/resources/lang/zh_TW/oauth.php @@ -10,4 +10,5 @@ return [ 'authorization_request_desc' => '正在請求獲取您賬號的訪問權限', 'btn_approve' => '授權', 'btn_deny' => '取消', + 'skips_authorization' => '跳過授權', ]; From 73bd3a1eaac97a994c7e3820ae6121e0a9131e49 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 18 Mar 2024 02:57:55 +0800 Subject: [PATCH 7/7] fix oauth client secret --- app/Filament/Resources/Oauth/ClientResource.php | 4 ++-- app/Models/OauthClient.php | 7 +++++++ include/constants.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Filament/Resources/Oauth/ClientResource.php b/app/Filament/Resources/Oauth/ClientResource.php index 6c4c47dd..fd143cac 100644 --- a/app/Filament/Resources/Oauth/ClientResource.php +++ b/app/Filament/Resources/Oauth/ClientResource.php @@ -6,7 +6,7 @@ use App\Filament\OptionsTrait; use App\Filament\PageListSingle; use App\Filament\Resources\Oauth\ClientResource\Pages; use App\Filament\Resources\Oauth\ClientResource\RelationManagers; -use Laravel\Passport\Client; +use App\Models\OauthClient; use Filament\Forms; use Filament\Resources\Form; use Filament\Resources\Resource; @@ -19,7 +19,7 @@ class ClientResource extends Resource { use OptionsTrait; - protected static ?string $model = Client::class; + protected static ?string $model = OauthClient::class; protected static ?string $navigationIcon = 'heroicon-o-collection'; diff --git a/app/Models/OauthClient.php b/app/Models/OauthClient.php index 6c9de2f7..77bae9f5 100644 --- a/app/Models/OauthClient.php +++ b/app/Models/OauthClient.php @@ -2,10 +2,17 @@ namespace App\Models; +use Illuminate\Support\Str; use Laravel\Passport\Client; class OauthClient extends Client { + protected static function booted(): void + { + static::creating(function (OauthClient $model) { + $model->secret = Str::random(40); + }); + } public function skipsAuthorization(): bool { return (bool)$this->skips_authorization; diff --git a/include/constants.php b/include/constants.php index bfece3db..3f1f2a07 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@