graphOptions($tenant); } catch (ProviderConfigurationRequiredException $exception) { return [ 'success' => false, 'error_message' => $exception->getMessage(), 'requires_consent' => $exception->reasonCode === ProviderReasonCodes::ProviderConsentMissing, ]; } if ($options['tenant'] === null) { return [ 'success' => false, 'error_message' => 'Tenant ID is missing', 'requires_consent' => false, ]; } try { $response = $this->graphClient->getOrganization($options); } catch (Throwable $throwable) { $mapped = GraphErrorMapper::fromThrowable($throwable, ['tenant' => $options['tenant']]); return [ 'success' => false, 'error_message' => $mapped->getMessage(), 'requires_consent' => $this->requiresConsent($mapped->getMessage()), ]; } if ($response->failed()) { $message = $response->errors[0]['message'] ?? $response->errors[0] ?? 'Graph connectivity failed'; return [ 'success' => false, 'error_message' => is_string($message) ? $message : json_encode($message), 'requires_consent' => $this->requiresConsent((string) $message), ]; } return ['success' => true, 'error_message' => null, 'requires_consent' => false]; } /** * @return array */ public function graphOptions(Tenant $tenant): array { return $this->graphOptionsResolver->resolveForTenant($tenant); } private function requiresConsent(string $message): bool { return str_contains(strtolower($message), 'consent'); } }