- Introduced new components and services for OIDC app creation, enabling dynamic handling of app types, URIs, and user roles. - Added support for uploading and managing logos for connected apps. - Implemented `ClientCreationFactory` and related factories for modular OIDC client generation. - Updated UI to enhance app creation flow with post-creation credential display and improved validations. - Refactored backend with `OidcService` for streamlined OIDC app creation and management.
60 lines
2.0 KiB
PHP
60 lines
2.0 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;
|
|
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
|
|
{
|
|
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,
|
|
logo: $logo,
|
|
)
|
|
);
|
|
|
|
$clientData = $this->clientCreationFactory->for($data->type)->create($data);
|
|
DB::commit();
|
|
|
|
// remove sensitive data
|
|
$appData->settings = null;
|
|
|
|
return new CreatedApplicationData(
|
|
application: $appData,
|
|
clientCredentials: $clientData,
|
|
);
|
|
} catch (Throwable $e) {
|
|
DB::rollBack();
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|