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, ]); } }