TenantAtlas/app/Services/Providers/ProviderIdentityResolution.php
ahmido bab01f07a9 feat: standardize platform provider identity (#166)
## Summary
- standardize Microsoft provider connections around explicit platform vs dedicated identity modes
- centralize admin-consent URL and runtime identity resolution so platform flows no longer fall back to tenant-local credentials
- add migration classification, richer consent and verification state handling, dedicated override management, and focused regression coverage

## Validation
- focused repo test coverage was added across provider identity, onboarding, audit, policy, guard, and migration flows
- latest explicit passing run in the workspace: `vendor/bin/sail artisan test --compact tests/Feature/AdminConsentCallbackTest.php tests/Feature/Audit/ProviderConnectionConsentAuditTest.php`

## Notes
- branch includes the full Spec 137 artifact set under `specs/137-platform-provider-identity/`
- target base branch: `dev`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #166
2026-03-13 16:29:08 +00:00

92 lines
2.9 KiB
PHP

<?php
namespace App\Services\Providers;
use App\Support\Providers\ProviderConnectionType;
use App\Support\Providers\ProviderReasonCodes;
use Illuminate\Support\Str;
use RuntimeException;
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,
);
}
/**
* @param array<string, mixed> $overrides
* @return array<string, mixed>
*/
public function graphOptions(array $overrides = []): array
{
if (! $this->resolved || $this->effectiveClientId === null || $this->clientSecret === null) {
throw new RuntimeException($this->message ?? 'Provider identity could not be resolved.');
}
return array_merge([
'tenant' => $this->tenantContext,
'client_id' => $this->effectiveClientId,
'client_secret' => $this->clientSecret,
'client_request_id' => (string) Str::uuid(),
], $overrides);
}
public function effectiveReasonCode(): string
{
return $this->reasonCode ?? ProviderReasonCodes::UnknownError;
}
}