## 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
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Providers;
|
|
|
|
use App\Models\ProviderConnection;
|
|
use RuntimeException;
|
|
|
|
final class AdminConsentUrlFactory
|
|
{
|
|
public function __construct(
|
|
private readonly ProviderIdentityResolver $identityResolver,
|
|
) {}
|
|
|
|
public function make(ProviderConnection $connection, string $state): string
|
|
{
|
|
$normalizedState = trim($state);
|
|
|
|
if ($normalizedState === '') {
|
|
throw new RuntimeException('Consent state is required.');
|
|
}
|
|
|
|
$resolution = $this->identityResolver->resolve($connection);
|
|
|
|
if (! $resolution->resolved || $resolution->effectiveClientId === null || $resolution->redirectUri === null) {
|
|
throw new RuntimeException($resolution->message ?? 'Provider identity could not be resolved for admin consent.');
|
|
}
|
|
|
|
$tenantSegment = trim($resolution->tenantContext) !== '' ? trim($resolution->tenantContext) : 'organizations';
|
|
|
|
return "https://login.microsoftonline.com/{$tenantSegment}/v2.0/adminconsent?".http_build_query([
|
|
'client_id' => $resolution->effectiveClientId,
|
|
'redirect_uri' => $resolution->redirectUri,
|
|
'scope' => (string) config('graph.scope', 'https://graph.microsoft.com/.default'),
|
|
'state' => $normalizedState,
|
|
]);
|
|
}
|
|
}
|