= 7f02209631 Feat: Add OIDC app creation feature with access URL support, Hide SAML, Microservice
- Introduced tests for OIDC app creation, including validation for access URL formatting.
- Updated enums and services to streamline application type and protocol handling.
- Added `accessUrl` support across backend, services, and UI to enhance app functionality and user accessibility.
- Refactored and commented out unused enum values and providers to improve maintainability.
2026-06-22 05:54:36 +00:00

78 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Applications\OIDC;
use App\Data\Application\{CreatedApplicationData, StoreOIDCAppData};
use App\Data\ConnectedApp\ConnectAppRequest;
use App\Enums\{ConnectionProtocolEnum, ConnectionStatusEnum};
use App\Models\{ConnectionProtocol, ConnectionStatus};
use App\Services\{ApplicationLogoUploader, ConnectedAppService};
use App\Services\Applications\OIDC\Factory\ClientCreationFactory;
use Illuminate\Support\Facades\{DB, Log};
use Illuminate\Support\Str;
use Throwable;
readonly class OidcService
{
public function __construct(
private ClientCreationFactory $clientCreationFactory,
private ApplicationLogoUploader $logoUploader,
private ConnectedAppService $connectedAppService,
) {}
/**
* @throws Throwable
*/
public function createApp(StoreOIDCAppData $data): CreatedApplicationData
{
Log::info('Creating OIDC app', [
'name' => $data->name,
'type' => $data->type,
]);
try {
DB::beginTransaction();
$logo = $this->logoUploader->store($data->logo);
$appData = $this->connectedAppService->create(
new ConnectAppRequest(
name: $data->name,
connectionProtocolId: ConnectionProtocol::query()->where('name', ConnectionProtocolEnum::OIDC->value)->first()->id,
connectionProviderId: 0,
slug: Str::slug($data->name),
connectionStatusId: ConnectionStatus::query()->where('name', ConnectionStatusEnum::Connected->value)->first()->id,
settings: [
'access_url' => $data->accessUrl,
],
logo: $logo,
)
);
$clientData = $this->clientCreationFactory->for($data->type)->create($data);
DB::commit();
// remove sensitive data
$appData->settings = null;
Log::info('OIDC app created', [
'name' => $data->name,
'type' => $data->type,
'clientId' => isset($clientData->clientId),
'clientSecret' => isset($clientData->clientSecret),
]);
return new CreatedApplicationData(
application: $appData,
clientCredentials: $clientData,
);
} catch (Throwable $e) {
DB::rollBack();
Log::error('Failed to create OIDC app', [
'name' => $data->name,
'type' => $data->type,
]);
throw $e;
}
}
}