2025-01-15 18:29:06 +01:00
< ? php
2025-07-01 21:33:11 -04:00
namespace App\Extensions\OAuth\Schemas ;
2025-01-15 18:29:06 +01:00
2025-02-07 17:28:06 +01:00
use Filament\Forms\Components\ColorPicker ;
2025-01-15 18:29:06 +01:00
use Filament\Forms\Components\TextInput ;
2025-11-01 02:09:20 +08:00
use Filament\Infolists\Components\TextEntry ;
use Filament\Schemas\Components\Wizard\Step ;
use Illuminate\Support\Facades\Blade ;
use Illuminate\Support\HtmlString ;
2025-01-15 18:29:06 +01:00
use SocialiteProviders\Authentik\Provider ;
2025-07-01 21:33:11 -04:00
final class AuthentikSchema extends OAuthSchema
2025-01-15 18:29:06 +01:00
{
public function getId () : string
{
return 'authentik' ;
}
2025-07-01 21:33:11 -04:00
public function getSocialiteProvider () : string
2025-01-15 18:29:06 +01:00
{
return Provider :: class ;
}
public function getServiceConfig () : array
{
2025-11-01 02:09:20 +08:00
return array_merge ( parent :: getServiceConfig (), [
2025-02-07 17:28:06 +01:00
'base_url' => env ( 'OAUTH_AUTHENTIK_BASE_URL' ),
2025-11-01 02:09:20 +08:00
]);
}
public function getSetupSteps () : array
{
return array_merge ([
Step :: make ( 'Create Authentik Application' )
-> schema ([
TextEntry :: make ( 'create_application' )
-> hiddenLabel ()
-> state ( new HtmlString ( Blade :: render ( '<p>On your Authentik dashboard select <b>Applications</b>, then select <b>Create with Provider</b>.</p><p>On the creation step select <b>OAuth2/OpenID Provider</b> and on the configure step set <b>Redirect URIs/Origins</b> to the value below.</p>' ))),
TextInput :: make ( '_noenv_callback' )
-> label ( 'Callback URL' )
-> dehydrated ()
-> disabled ()
-> hintCopy ()
-> default ( fn () => url ( '/auth/oauth/callback/authentik' )),
]),
], parent :: getSetupSteps ());
2025-01-15 18:29:06 +01:00
}
public function getSettingsForm () : array
{
return array_merge ( parent :: getSettingsForm (), [
TextInput :: make ( 'OAUTH_AUTHENTIK_BASE_URL' )
-> label ( 'Base URL' )
-> placeholder ( 'Base URL' )
-> columnSpan ( 2 )
-> required ()
-> url ()
-> autocomplete ( false )
-> default ( env ( 'OAUTH_AUTHENTIK_BASE_URL' )),
TextInput :: make ( 'OAUTH_AUTHENTIK_DISPLAY_NAME' )
-> label ( 'Display Name' )
-> placeholder ( 'Display Name' )
-> autocomplete ( false )
-> default ( env ( 'OAUTH_AUTHENTIK_DISPLAY_NAME' , 'Authentik' )),
2025-02-07 17:28:06 +01:00
ColorPicker :: make ( 'OAUTH_AUTHENTIK_DISPLAY_COLOR' )
-> label ( 'Display Color' )
-> placeholder ( '#fd4b2d' )
-> default ( env ( 'OAUTH_AUTHENTIK_DISPLAY_COLOR' , '#fd4b2d' ))
-> hex (),
2025-01-15 18:29:06 +01:00
]);
}
public function getName () : string
{
2025-03-08 19:56:06 -05:00
return env ( 'OAUTH_AUTHENTIK_DISPLAY_NAME' , 'Authentik' );
2025-01-15 18:29:06 +01:00
}
public function getHexColor () : string
{
2025-03-08 19:56:06 -05:00
return env ( 'OAUTH_AUTHENTIK_DISPLAY_COLOR' , '#fd4b2d' );
2025-01-15 18:29:06 +01:00
}
}