TenantAtlas/apps/platform/app/Services/Providers/ProviderIdentityResolution.php
Ahmed Darrazi 079a7dcaf3
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 57s
feat: harden provider boundaries
2026-04-24 22:55:44 +02:00

72 lines
2.2 KiB
PHP

<?php
namespace App\Services\Providers;
use App\Support\Providers\ProviderConnectionType;
use App\Support\Providers\ProviderReasonCodes;
final class ProviderIdentityResolution
{
private function __construct(
public readonly bool $resolved,
public readonly ProviderConnectionType $connectionType,
public readonly string $tenantContext,
public readonly ?string $effectiveClientId,
public readonly string $credentialSource,
public readonly ?string $clientSecret,
public readonly ?string $authorityTenant,
public readonly ?string $redirectUri,
public readonly ?string $reasonCode,
public readonly ?string $message,
) {}
public static function resolved(
ProviderConnectionType $connectionType,
string $tenantContext,
string $effectiveClientId,
string $credentialSource,
?string $clientSecret,
?string $authorityTenant,
?string $redirectUri,
): self {
return new self(
resolved: true,
connectionType: $connectionType,
tenantContext: $tenantContext,
effectiveClientId: $effectiveClientId,
credentialSource: $credentialSource,
clientSecret: $clientSecret,
authorityTenant: $authorityTenant,
redirectUri: $redirectUri,
reasonCode: null,
message: null,
);
}
public static function blocked(
ProviderConnectionType $connectionType,
string $tenantContext,
string $credentialSource,
string $reasonCode,
?string $message = null,
): self {
return new self(
resolved: false,
connectionType: $connectionType,
tenantContext: $tenantContext,
effectiveClientId: null,
credentialSource: $credentialSource,
clientSecret: null,
authorityTenant: null,
redirectUri: null,
reasonCode: ProviderReasonCodes::isKnown($reasonCode) ? $reasonCode : ProviderReasonCodes::UnknownError,
message: $message,
);
}
public function effectiveReasonCode(): string
{
return $this->reasonCode ?? ProviderReasonCodes::UnknownError;
}
}