Some checks are pending
Main Confidence / confidence (push) Waiting to run
## Summary - add a shared provider target-scope descriptor, normalizer, identity-context metadata, and surface-summary layer - update provider connection list, detail, create, edit, and onboarding surfaces to use neutral target-scope vocabulary while keeping Microsoft identity contextual - align provider connection audit and resolver output with the neutral target-scope contract and add focused guard/unit/feature coverage for regressions ## Validation - browser smoke: opened the tenant-scoped provider connection list, drilled into detail, and verified the edit/create surfaces in local admin context ## Notes - this PR comes from the session branch created for the active feature work - no additional runtime or persistence layer was introduced in this slice Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #274
123 lines
4.6 KiB
PHP
123 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Providers;
|
|
|
|
use App\Support\Providers\ProviderConnectionType;
|
|
use App\Support\Providers\ProviderReasonCodes;
|
|
use App\Support\Providers\TargetScope\ProviderConnectionTargetScopeDescriptor;
|
|
use App\Support\Providers\TargetScope\ProviderIdentityContextMetadata;
|
|
|
|
final class ProviderIdentityResolution
|
|
{
|
|
/**
|
|
* @param list<ProviderIdentityContextMetadata> $contextualIdentityDetails
|
|
*/
|
|
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 readonly ?ProviderConnectionTargetScopeDescriptor $targetScope,
|
|
public readonly array $contextualIdentityDetails,
|
|
) {}
|
|
|
|
public static function resolved(
|
|
ProviderConnectionType $connectionType,
|
|
string $tenantContext,
|
|
string $effectiveClientId,
|
|
string $credentialSource,
|
|
?string $clientSecret,
|
|
?string $authorityTenant,
|
|
?string $redirectUri,
|
|
?ProviderConnectionTargetScopeDescriptor $targetScope = null,
|
|
array $contextualIdentityDetails = [],
|
|
): self {
|
|
return new self(
|
|
resolved: true,
|
|
connectionType: $connectionType,
|
|
tenantContext: $tenantContext,
|
|
effectiveClientId: $effectiveClientId,
|
|
credentialSource: $credentialSource,
|
|
clientSecret: $clientSecret,
|
|
authorityTenant: $authorityTenant,
|
|
redirectUri: $redirectUri,
|
|
reasonCode: null,
|
|
message: null,
|
|
targetScope: $targetScope ?? self::targetScopeFromContext($tenantContext),
|
|
contextualIdentityDetails: $contextualIdentityDetails !== []
|
|
? $contextualIdentityDetails
|
|
: self::contextualIdentityDetails($tenantContext, $authorityTenant, $redirectUri),
|
|
);
|
|
}
|
|
|
|
public static function blocked(
|
|
ProviderConnectionType $connectionType,
|
|
string $tenantContext,
|
|
string $credentialSource,
|
|
string $reasonCode,
|
|
?string $message = null,
|
|
?ProviderConnectionTargetScopeDescriptor $targetScope = null,
|
|
array $contextualIdentityDetails = [],
|
|
): 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,
|
|
targetScope: $targetScope ?? (trim($tenantContext) !== '' ? self::targetScopeFromContext($tenantContext) : null),
|
|
contextualIdentityDetails: $contextualIdentityDetails !== []
|
|
? $contextualIdentityDetails
|
|
: self::contextualIdentityDetails($tenantContext),
|
|
);
|
|
}
|
|
|
|
public function effectiveReasonCode(): string
|
|
{
|
|
return $this->reasonCode ?? ProviderReasonCodes::UnknownError;
|
|
}
|
|
|
|
private static function targetScopeFromContext(string $tenantContext): ProviderConnectionTargetScopeDescriptor
|
|
{
|
|
$identifier = trim($tenantContext) !== '' ? trim($tenantContext) : 'organizations';
|
|
|
|
return ProviderConnectionTargetScopeDescriptor::fromInput(
|
|
provider: 'microsoft',
|
|
scopeKind: ProviderConnectionTargetScopeDescriptor::SCOPE_KIND_TENANT,
|
|
scopeIdentifier: $identifier,
|
|
scopeDisplayName: $identifier,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return list<ProviderIdentityContextMetadata>
|
|
*/
|
|
private static function contextualIdentityDetails(
|
|
string $tenantContext,
|
|
?string $authorityTenant = null,
|
|
?string $redirectUri = null,
|
|
): array {
|
|
$details = [
|
|
ProviderIdentityContextMetadata::microsoftTenantId($tenantContext),
|
|
ProviderIdentityContextMetadata::authorityTenant($authorityTenant),
|
|
ProviderIdentityContextMetadata::redirectUri($redirectUri),
|
|
];
|
|
|
|
return array_values(array_filter(
|
|
$details,
|
|
static fn (?ProviderIdentityContextMetadata $detail): bool => $detail instanceof ProviderIdentityContextMetadata,
|
|
));
|
|
}
|
|
}
|