2025-04-24 15:30:07 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\Oauth;
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
use Filament\Schemas\Schema;
|
|
|
|
|
use Filament\Forms\Components\TextInput;
|
|
|
|
|
use Filament\Forms\Components\Toggle;
|
|
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Tables\Columns\IconColumn;
|
|
|
|
|
use Filament\Actions\EditAction;
|
|
|
|
|
use Filament\Actions\DeleteAction;
|
|
|
|
|
use Filament\Actions\BulkActionGroup;
|
|
|
|
|
use Filament\Actions\DeleteBulkAction;
|
|
|
|
|
use App\Filament\Resources\Oauth\ProviderResource\Pages\ManageProviders;
|
2025-04-24 15:30:07 +07:00
|
|
|
use App\Filament\Resources\Oauth\ProviderResource\Pages;
|
|
|
|
|
use App\Filament\Resources\Oauth\ProviderResource\RelationManagers;
|
|
|
|
|
use App\Models\OauthProvider;
|
2025-05-01 14:18:30 +07:00
|
|
|
use App\Models\User;
|
2025-04-24 15:30:07 +07:00
|
|
|
use Filament\Forms;
|
|
|
|
|
use Filament\Resources\Resource;
|
|
|
|
|
use Filament\Tables;
|
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
2025-05-02 11:53:56 +07:00
|
|
|
use Nexus\Database\NexusDB;
|
|
|
|
|
use Ramsey\Uuid;
|
2025-04-24 15:30:07 +07:00
|
|
|
|
|
|
|
|
class ProviderResource extends Resource
|
|
|
|
|
{
|
|
|
|
|
protected static ?string $model = OauthProvider::class;
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-rectangle-stack';
|
2025-04-24 15:30:07 +07:00
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
protected static string | \UnitEnum | null $navigationGroup = 'Oauth';
|
2025-04-24 15:30:07 +07:00
|
|
|
|
|
|
|
|
protected static ?int $navigationSort = 5;
|
|
|
|
|
|
|
|
|
|
public static function getNavigationLabel(): string
|
|
|
|
|
{
|
|
|
|
|
return __('admin.sidebar.oauth_provider');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getBreadcrumb(): string
|
|
|
|
|
{
|
|
|
|
|
return self::getNavigationLabel();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
public static function form(Schema $schema): Schema
|
2025-04-24 15:30:07 +07:00
|
|
|
{
|
2025-09-21 18:07:38 +08:00
|
|
|
return $schema
|
|
|
|
|
->components([
|
|
|
|
|
TextInput::make('name')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('label.name'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('client_id')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.client_id'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('client_secret')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.secret'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('authorization_endpoint_url')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.authorization_endpoint_url'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('token_endpoint_url')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.token_endpoint_url'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('user_info_endpoint_url')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.user_info_endpoint_url'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('id_claim')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.id_claim'))
|
|
|
|
|
->required()
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('email_claim')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.email_claim'))
|
2025-05-02 14:22:35 +07:00
|
|
|
->required()
|
2025-04-24 15:30:07 +07:00
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('username_claim')
|
2025-05-02 14:22:35 +07:00
|
|
|
->label(__('oauth.username_claim'))
|
|
|
|
|
,
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('level_claim')
|
2025-05-01 14:18:30 +07:00
|
|
|
->label(__('oauth.level_claim'))
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('level_limit')
|
2025-05-01 14:18:30 +07:00
|
|
|
->numeric()
|
|
|
|
|
->label(__('oauth.level_limit'))
|
|
|
|
|
->helperText(__('oauth.level_limit_help'))
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('priority')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('label.priority'))
|
|
|
|
|
->default(0)
|
|
|
|
|
->numeric()
|
|
|
|
|
->helperText(__('label.priority_help'))
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
Toggle::make('enabled')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('label.enabled'))
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextInput::make('redirect')
|
2025-05-02 11:53:56 +07:00
|
|
|
->default(fn ($record) => OauthProvider::getCallbackUrl($record->uuid ?? self::getNewUuid()))
|
|
|
|
|
->disabled()
|
|
|
|
|
->label(__('oauth.redirect'))
|
|
|
|
|
->columnSpanFull()
|
|
|
|
|
,
|
2025-04-24 15:30:07 +07:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 11:53:56 +07:00
|
|
|
private static function getNewUuid(): string
|
|
|
|
|
{
|
|
|
|
|
return NexusDB::remember("new_oauth_provider_uuid", 86400 * 365, function () {
|
|
|
|
|
return UUid\v4();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 15:30:07 +07:00
|
|
|
public static function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->columns([
|
2025-09-21 18:07:38 +08:00
|
|
|
TextColumn::make('id'),
|
|
|
|
|
TextColumn::make('name')->label(__('label.name')),
|
|
|
|
|
TextColumn::make('client_id')->label(__('oauth.client_id')),
|
|
|
|
|
TextColumn::make('client_secret')->label(__('oauth.secret')),
|
|
|
|
|
TextColumn::make('authorization_endpoint_url')->label(__('oauth.authorization_endpoint_url')),
|
|
|
|
|
TextColumn::make('uuid')
|
2025-04-24 15:30:07 +07:00
|
|
|
->label(__('oauth.redirect'))
|
|
|
|
|
->formatStateUsing(fn ($state) => url("/oauth/callback/$state"))
|
|
|
|
|
,
|
2025-09-21 18:07:38 +08:00
|
|
|
TextColumn::make('priority')->label(__('label.priority')),
|
|
|
|
|
TextColumn::make('updated_at')->label(__('label.updated_at')),
|
|
|
|
|
TextColumn::make('level_limit')->label(__('oauth.level_limit')),
|
|
|
|
|
IconColumn::make('enabled')->boolean()->label(__('label.enabled')),
|
2025-04-24 15:30:07 +07:00
|
|
|
])
|
|
|
|
|
->defaultSort('priority', 'desc')
|
|
|
|
|
->filters([
|
|
|
|
|
//
|
|
|
|
|
])
|
2025-09-21 18:07:38 +08:00
|
|
|
->recordActions([
|
|
|
|
|
EditAction::make(),
|
|
|
|
|
DeleteAction::make(),
|
2025-04-24 15:30:07 +07:00
|
|
|
])
|
2025-09-21 18:07:38 +08:00
|
|
|
->toolbarActions([
|
|
|
|
|
BulkActionGroup::make([
|
|
|
|
|
DeleteBulkAction::make(),
|
2025-04-24 15:30:07 +07:00
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2025-09-21 18:07:38 +08:00
|
|
|
'index' => ManageProviders::route('/'),
|
2025-04-24 15:30:07 +07:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|