mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 09:26:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			120 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Extensions\OAuth\Schemas;
 | |
| 
 | |
| use App\Extensions\OAuth\OAuthSchemaInterface;
 | |
| use Filament\Forms\Components\Component;
 | |
| use Filament\Forms\Components\TextInput;
 | |
| use Filament\Forms\Components\Toggle;
 | |
| use Filament\Forms\Components\Wizard\Step;
 | |
| use Filament\Forms\Set;
 | |
| use Illuminate\Support\Str;
 | |
| 
 | |
| abstract class OAuthSchema implements OAuthSchemaInterface
 | |
| {
 | |
|     abstract public function getId(): string;
 | |
| 
 | |
|     public function getSocialiteProvider(): ?string
 | |
|     {
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public function getServiceConfig(): array
 | |
|     {
 | |
|         $id = Str::upper($this->getId());
 | |
| 
 | |
|         return [
 | |
|             'client_id' => env("OAUTH_{$id}_CLIENT_ID"),
 | |
|             'client_secret' => env("OAUTH_{$id}_CLIENT_SECRET"),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @return Component[]
 | |
|      */
 | |
|     public function getSettingsForm(): array
 | |
|     {
 | |
|         $id = Str::upper($this->getId());
 | |
| 
 | |
|         return [
 | |
|             TextInput::make("OAUTH_{$id}_CLIENT_ID")
 | |
|                 ->label('Client ID')
 | |
|                 ->placeholder('Client ID')
 | |
|                 ->columnSpan(2)
 | |
|                 ->required()
 | |
|                 ->password()
 | |
|                 ->revealable()
 | |
|                 ->autocomplete(false)
 | |
|                 ->default(env("OAUTH_{$id}_CLIENT_ID")),
 | |
|             TextInput::make("OAUTH_{$id}_CLIENT_SECRET")
 | |
|                 ->label('Client Secret')
 | |
|                 ->placeholder('Client Secret')
 | |
|                 ->columnSpan(2)
 | |
|                 ->required()
 | |
|                 ->password()
 | |
|                 ->revealable()
 | |
|                 ->autocomplete(false)
 | |
|                 ->default(env("OAUTH_{$id}_CLIENT_SECRET")),
 | |
|             Toggle::make("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS")
 | |
|                 ->label(trans('admin/setting.oauth.create_missing_users'))
 | |
|                 ->columnSpanFull()
 | |
|                 ->inline(false)
 | |
|                 ->onIcon('tabler-check')
 | |
|                 ->offIcon('tabler-x')
 | |
|                 ->onColor('success')
 | |
|                 ->offColor('danger')
 | |
|                 ->formatStateUsing(fn ($state): bool => (bool) $state)
 | |
|                 ->afterStateUpdated(fn ($state, Set $set) => $set("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS", (bool) $state))
 | |
|                 ->default(env("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS")),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @return Step[]
 | |
|      */
 | |
|     public function getSetupSteps(): array
 | |
|     {
 | |
|         return [
 | |
|             Step::make('OAuth Config')
 | |
|                 ->columns(4)
 | |
|                 ->schema($this->getSettingsForm()),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     public function getName(): string
 | |
|     {
 | |
|         return Str::title($this->getId());
 | |
|     }
 | |
| 
 | |
|     public function getConfigKey(): string
 | |
|     {
 | |
|         $id = Str::upper($this->getId());
 | |
| 
 | |
|         return "OAUTH_{$id}_ENABLED";
 | |
|     }
 | |
| 
 | |
|     public function getIcon(): ?string
 | |
|     {
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public function getHexColor(): ?string
 | |
|     {
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public function isEnabled(): bool
 | |
|     {
 | |
|         $id = Str::upper($this->getId());
 | |
| 
 | |
|         return env("OAUTH_{$id}_ENABLED", false);
 | |
|     }
 | |
| 
 | |
|     public function shouldCreateMissingUsers(): bool
 | |
|     {
 | |
|         $id = Str::upper($this->getId());
 | |
| 
 | |
|         return env("OAUTH_{$id}_SHOULD_CREATE_MISSING_USERS", false);
 | |
|     }
 | |
| }
 | 
