@@ -54,7 +54,7 @@ public function loaded()
54
54
}
55
55
$ this ->setAuthSimple ()
56
56
->setIdentityProviders ();
57
- return true ;
57
+ return true ;
58
58
}
59
59
60
60
/**
@@ -94,40 +94,50 @@ public function getIdentityProviders()
94
94
}
95
95
96
96
/**
97
- * Set the available Identity Providers list .
98
- * @return object This SimpleSAML object.
97
+ * Get an array of available Identity Providers.
98
+ * @return array array
99
99
*/
100
- protected function setIdentityProviders ()
100
+ public function identityProviders ()
101
101
{
102
- if (!method_exists ('\SimpleSAML\Configuration ' , 'getConfig ' )) {
103
- return $ this ;
104
- }
105
-
106
- try {
107
- // Get the authsources file, which should contain the config.
108
- $ authsource = \SimpleSAML \Configuration::getConfig ('authsources.php ' );
109
- } catch (\Exception $ e ) {
110
- $ error = new \WP_Error ('simplesaml_configuration_error ' , $ e ->getMessage ());
111
- $ this ->errorOnLoaded ($ error );
112
- return $ this ;
102
+ // Initialize the metadata storage handler
103
+ $ metadataHandler = \SimpleSAML \Metadata \MetaDataStorageHandler::getMetadataHandler ();
104
+
105
+ // Load all available metadata entities
106
+ $ entityList = $ metadataHandler ->getList ();
107
+
108
+ // Array to store IdP metadata
109
+ $ idpMetadata = [];
110
+
111
+ foreach (array_keys ($ entityList ) as $ entityId ) {
112
+ try {
113
+ // Fetch metadata for the entity from metarefresh cache
114
+ $ metadata = $ metadataHandler ->getMetaDataConfig ($ entityId , 'saml20-idp-remote ' );
115
+
116
+ // Store only IdP metadata
117
+ if ($ metadata !== null ) {
118
+ $ idpMetadata [$ entityId ] = $ metadata ->toArray ();
119
+ }
120
+ } catch (\Exception $ e ) {
121
+ error_log ("Error retrieving metadata for entity $ entityId: " . $ e ->getMessage ());
122
+ }
113
123
}
114
124
115
- // Get just the specified authsource config values.
116
- $ authsource = $ authsource ->toArray ();
117
- $ idp = $ authsource [$ this ->options ->simplesaml_auth_source ]['idp ' ] ?? 'null ' ;
125
+ return $ idpMetadata ;
126
+ }
118
127
119
- $ saml20IdpRemoteFile = dirname ($ this ->simplesamlInclude , 2 ) . '/metadata/saml20-idp-remote.php ' ;
120
- if (!file_exists ($ saml20IdpRemoteFile )) {
121
- return $ this ;
122
- }
123
- // Load $metadata array.
124
- require_once ($ saml20IdpRemoteFile );
128
+ /**
129
+ * Set the available Identity Providers list.
130
+ * @return object This SimpleSAML object.
131
+ */
132
+ protected function setIdentityProviders ()
133
+ {
134
+ $ idpMetadata = $ this ->identityProviders ();
125
135
126
- $ metadata = $ metadata ?? [];
127
136
$ locale = get_locale ();
128
137
$ lang = explode ('_ ' , $ locale )[0 ];
138
+
129
139
$ idps = [];
130
- foreach ($ metadata as $ key => $ value ) {
140
+ foreach ($ idpMetadata as $ key => $ value ) {
131
141
if (isset ($ value ['name ' ][$ lang ])) {
132
142
$ name = $ value ['name ' ][$ lang ];
133
143
} elseif (isset ($ value ['name ' ]) && is_string ($ value ['name ' ])) {
@@ -138,12 +148,6 @@ protected function setIdentityProviders()
138
148
$ idps [$ key ] = $ name ;
139
149
}
140
150
141
- if ($ idp && isset ($ idps [$ idp ])) {
142
- $ idps = [
143
- $ idp => $ idps [$ idp ]
144
- ];
145
- }
146
-
147
151
$ this ->identityProviders = $ idps ;
148
152
return $ this ;
149
153
}
0 commit comments