From 4bdf6efddd856a2ac60c0e0865c74be88b2a9f39 Mon Sep 17 00:00:00 2001 From: jmf3658 Date: Thu, 19 Dec 2024 11:24:52 -0700 Subject: [PATCH] View resulting XML metadata from configuration --- wp-saml-auth.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wp-saml-auth.php b/wp-saml-auth.php index 1e60de1..955fd4e 100644 --- a/wp-saml-auth.php +++ b/wp-saml-auth.php @@ -189,3 +189,33 @@ function wpsa_filter_option( $value, $option_name ) { */ require_once __DIR__ . '/inc/class-wp-saml-auth-options.php'; WP_SAML_Auth_Options::get_instance(); + + +add_action('parse_request', 'get_sp_metadata', 0); + +/** + * Provides a display at /saml/metadata for viewing the XML. + */ +function get_sp_metadata() { + $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; + $path = parse_url($url, PHP_URL_PATH); + if (trim($path, '\/') !== 'saml/metadata') { + return; + } + $instance = WP_SAML_Auth::get_instance(); + $provider = $instance->get_provider(); + $settings = $provider->getSettings(); + $metadata = null; + try { + $metadata = $settings->getSPMetadata(); + $errors = $settings->validateMetadata($metadata); + } catch (\Exception $e) { + $errors = $e->getMessage(); + } + if ($errors) { + wp_die(esc_html__('Invalid SAML settings. Contact your administrator.', 'wp-saml-auth')); + } + header('Content-Type: text/xml'); + echo $metadata; + exit; +}