diff --git a/pocketid-provider/src/Extensions/OAuth/Schemas/PocketIDSchema.php b/pocketid-provider/src/Extensions/OAuth/Schemas/PocketIDSchema.php new file mode 100644 index 0000000..13da881 --- /dev/null +++ b/pocketid-provider/src/Extensions/OAuth/Schemas/PocketIDSchema.php @@ -0,0 +1,143 @@ + env('OAUTH_POCKETID_BASE_URL'), + ]); + } + + /** + * Provide setup steps required to configure Pocket ID as an OAuth provider. + * + * Returns an array of setup Step instances that guide the user through configuring a Pocket ID application; + * the steps include rendered HTML instructions and a disabled TextInput showing the required callback URL. + * + * @return array An array of Step objects for the setup UI, including an instructional HTML entry and a read-only callback URL field. + */ + public function getSetupSteps(): array + { + return array_merge([ + Step::make('Configure Pocket ID Application') + ->schema([ + TextEntry::make('instructions') + ->hiddenLabel() + ->state(new HtmlString(Blade::render(' +
    +
  1. Log in to your Pocket ID instance
  2. +
  3. Navigate to your application or create a new OAuth application
  4. +
  5. Copy the Client ID and Client Secret from your Pocket ID application
  6. +
  7. Configure the redirect URL shown below in your Pocket ID application settings
  8. +
+ '))), + TextInput::make('_noenv_callback') + ->label('Callback URL') + ->dehydrated() + ->disabled() + ->default(fn () => url('/auth/oauth/callback/pocketid')), + ]), + ], parent::getSetupSteps()); + } + + /** + * Builds the settings form fields for the Pocket ID OAuth provider. + * + * Returns the provider-specific settings merged with the parent form and includes: + * - `OAUTH_POCKETID_BASE_URL`: base URL for the Pocket ID service (URL-validated). + * - `OAUTH_POCKETID_DISPLAY_NAME`: user-facing display name for the provider. + * - `OAUTH_POCKETID_DISPLAY_COLOR`: hex color used for provider display. + * + * @return array An array of form field definitions for the settings form. + */ + public function getSettingsForm(): array + { + return array_merge(parent::getSettingsForm(), [ + TextInput::make('OAUTH_POCKETID_BASE_URL') + ->label('Base URL') + ->placeholder('https://id.example.com') + ->columnSpan(2) + ->required() + ->url() + ->autocomplete(false) + ->default(env('OAUTH_POCKETID_BASE_URL')), + TextInput::make('OAUTH_POCKETID_DISPLAY_NAME') + ->label('Display Name') + ->placeholder('Pocket ID') + ->autocomplete(false) + ->default(env('OAUTH_POCKETID_DISPLAY_NAME', 'Pocket ID')), + ColorPicker::make('OAUTH_POCKETID_DISPLAY_COLOR') + ->label('Display Color') + ->placeholder('#000000') + ->default(env('OAUTH_POCKETID_DISPLAY_COLOR', '#000000')) + ->hex(), + ]); + } + + /** + * Get the display name for the Pocket ID provider. + * + * @return string The display name from the `OAUTH_POCKETID_DISPLAY_NAME` environment variable, or `'Pocket ID'` if not set. + */ + public function getName(): string + { + return env('OAUTH_POCKETID_DISPLAY_NAME', 'Pocket ID'); + } + + /** + * Gets the UI icon identifier for the provider. + * + * @return string The icon identifier used to represent the provider (e.g., 'heroicon-o-identification'). + */ + public function getIcon(): string + { + return 'heroicon-o-identification'; + } + + /** + * Get the provider's display color as a hex string. + * + * @return string The hex color used for the provider's display (e.g., '#000000'); defaults to '#000000' if not configured. + */ + public function getHexColor(): string + { + return env('OAUTH_POCKETID_DISPLAY_COLOR', '#000000'); + } +} \ No newline at end of file diff --git a/pocketid-provider/src/PocketIDProviderPlugin.php b/pocketid-provider/src/PocketIDProviderPlugin.php new file mode 100644 index 0000000..7941284 --- /dev/null +++ b/pocketid-provider/src/PocketIDProviderPlugin.php @@ -0,0 +1,41 @@ +/Resources" inside this plugin and maps them to the + * PHP namespace "Ebnater\\PocketIDProvider\\Filament\\\\Resources". + * + * @param \Filament\Panel $panel The Filament panel whose resources should be discovered and registered. + */ + public function register(Panel $panel): void + { + $id = str($panel->getId())->title(); + + $panel->discoverResources(plugin_path($this->getId(), "src/Filament/$id/Resources"), "Ebnater\\PocketIDProvider\\Filament\\$id\\Resources"); + } + + /** + * Execute boot-time initialization for the given Filament panel. + * + * @param Panel $panel The Filament panel instance the plugin is booting for. + */ +public function boot(Panel $panel): void {} +} \ No newline at end of file diff --git a/pocketid-provider/src/Providers/PocketIDProviderPluginProvider.php b/pocketid-provider/src/Providers/PocketIDProviderPluginProvider.php new file mode 100644 index 0000000..9bf5aa8 --- /dev/null +++ b/pocketid-provider/src/Providers/PocketIDProviderPluginProvider.php @@ -0,0 +1,21 @@ +app->make(OAuthService::class); + $service->register(new PocketIDSchema()); + } +} \ No newline at end of file