|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Ebnater\PocketIDProvider\Extensions\OAuth\Schemas; |
| 4 | + |
| 5 | +use App\Extensions\OAuth\Schemas\OAuthSchema; |
| 6 | +use Filament\Forms\Components\ColorPicker; |
| 7 | +use Filament\Forms\Components\TextInput; |
| 8 | +use Filament\Infolists\Components\TextEntry; |
| 9 | +use Filament\Schemas\Components\Wizard\Step; |
| 10 | +use Illuminate\Support\Facades\Blade; |
| 11 | +use Illuminate\Support\HtmlString; |
| 12 | +use SocialiteProviders\PocketID\Provider; |
| 13 | + |
| 14 | +final class PocketIDSchema extends OAuthSchema |
| 15 | +{ |
| 16 | + public function getId(): string |
| 17 | + { |
| 18 | + return 'pocketid'; |
| 19 | + } |
| 20 | + |
| 21 | + public function getSocialiteProvider(): string |
| 22 | + { |
| 23 | + return Provider::class; |
| 24 | + } |
| 25 | + |
| 26 | + public function getServiceConfig(): array |
| 27 | + { |
| 28 | + return array_merge(parent::getServiceConfig(), [ |
| 29 | + 'base_url' => env('OAUTH_POCKETID_BASE_URL'), |
| 30 | + ]); |
| 31 | + } |
| 32 | + |
| 33 | + public function getSetupSteps(): array |
| 34 | + { |
| 35 | + return array_merge([ |
| 36 | + Step::make('Configure Pocket ID Application') |
| 37 | + ->schema([ |
| 38 | + TextEntry::make('instructions') |
| 39 | + ->hiddenLabel() |
| 40 | + ->state(new HtmlString(Blade::render(' |
| 41 | + <ol class="list-decimal list-inside space-y-1"> |
| 42 | + <li>Log in to your Pocket ID instance</li> |
| 43 | + <li>Navigate to your application or create a new OAuth application</li> |
| 44 | + <li>Copy the <strong>Client ID</strong> and <strong>Client Secret</strong> from your Pocket ID application</li> |
| 45 | + <li>Configure the redirect URL shown below in your Pocket ID application settings</li> |
| 46 | + </ol> |
| 47 | + '))), |
| 48 | + TextInput::make('_noenv_callback') |
| 49 | + ->label('Callback URL') |
| 50 | + ->dehydrated() |
| 51 | + ->disabled() |
| 52 | + ->default(fn () => url('/auth/oauth/callback/pocketid')), |
| 53 | + ]), |
| 54 | + ], parent::getSetupSteps()); |
| 55 | + } |
| 56 | + |
| 57 | + public function getSettingsForm(): array |
| 58 | + { |
| 59 | + return array_merge(parent::getSettingsForm(), [ |
| 60 | + TextInput::make('OAUTH_POCKETID_BASE_URL') |
| 61 | + ->label('Base URL') |
| 62 | + ->placeholder('https://id.example.com') |
| 63 | + ->columnSpan(2) |
| 64 | + ->required() |
| 65 | + ->url() |
| 66 | + ->autocomplete(false) |
| 67 | + ->default(env('OAUTH_POCKETID_BASE_URL')), |
| 68 | + TextInput::make('OAUTH_POCKETID_DISPLAY_NAME') |
| 69 | + ->label('Display Name') |
| 70 | + ->placeholder('Pocket ID') |
| 71 | + ->autocomplete(false) |
| 72 | + ->default(env('OAUTH_POCKETID_DISPLAY_NAME', 'Pocket ID')), |
| 73 | + ColorPicker::make('OAUTH_POCKETID_DISPLAY_COLOR') |
| 74 | + ->label('Display Color') |
| 75 | + ->placeholder('#000000') |
| 76 | + ->default(env('OAUTH_POCKETID_DISPLAY_COLOR', '#000000')) |
| 77 | + ->hex(), |
| 78 | + ]); |
| 79 | + } |
| 80 | + |
| 81 | + public function getName(): string |
| 82 | + { |
| 83 | + return env('OAUTH_POCKETID_DISPLAY_NAME', 'Pocket ID'); |
| 84 | + } |
| 85 | + |
| 86 | + public function getIcon(): string |
| 87 | + { |
| 88 | + return 'tabler-id'; |
| 89 | + } |
| 90 | + |
| 91 | + public function getHexColor(): string |
| 92 | + { |
| 93 | + return env('OAUTH_POCKETID_DISPLAY_COLOR', '#000000'); |
| 94 | + } |
| 95 | +} |
0 commit comments