MCPcopy Create free account
hub / github.com/error311/FileRise / applyOidcGroupsToPro

Method applyOidcGroupsToPro

src/FileRise/Domain/AuthModel.php:153–253  ·  view source on GitHub ↗

* Map OIDC groups into FileRise Pro groups (additive only – we never remove membership). * * @param string $username Local FileRise username * @param array $groupSlugs Array of group keys coming from the IdP, * already filtered by FR_OIDC_GROUP_PREFIX. */

(string $username, array $groupSlugs)

Source from the content-addressed store, hash-verified

151 * already filtered by FR_OIDC_GROUP_PREFIX.
152 */
153 public static function applyOidcGroupsToPro(string $username, array $groupSlugs): void
154 {
155 if (empty($groupSlugs)) {
156 return;
157 }
158 if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE) {
159 return;
160 }
161 if (!defined('FR_PRO_BUNDLE_DIR') || !FR_PRO_BUNDLE_DIR) {
162 return;
163 }
164
165 $bundleDir = rtrim(FR_PRO_BUNDLE_DIR, '/\\');
166 $proGroupsPath = $bundleDir . '/ProGroups.php';
167 if (!is_file($proGroupsPath)) {
168 error_log('[OIDC] ProGroups.php not found at ' . $proGroupsPath);
169 return;
170 }
171
172 require_once $proGroupsPath;
173 if (!class_exists('ProGroups')) {
174 error_log('[OIDC] ProGroups class not found after include.');
175 return;
176 }
177
178 $store = new \ProGroups($bundleDir);
179
180 // IMPORTANT: use load() so we preserve the full { "groups": ... } structure
181 $data = $store->load();
182 if (!is_array($data)) {
183 $data = [];
184 }
185 if (!isset($data['groups']) || !is_array($data['groups'])) {
186 $data['groups'] = [];
187 }
188
189 $groups = &$data['groups'];
190
191 // Build lowercase key index for case-insensitive lookups of existing groups
192 $keyIndex = [];
193 foreach ($groups as $key => $_info) {
194 $keyIndex[strtolower((string)$key)] = $key;
195 }
196
197 $uname = (string)$username;
198 $unameLc = strtolower($uname);
199
200 foreach ($groupSlugs as $rawSlug) {
201 $slug = trim((string)$rawSlug);
202 if ($slug === '') {
203 continue;
204 }
205
206 $slugLc = strtolower($slug);
207
208 // 1) Find existing group (case-insensitive) or auto-create a new one keyed by the slug
209 if (isset($keyIndex[$slugLc])) {
210 $groupKey = $keyIndex[$slugLc];

Callers 1

handleOidcFlowMethod · 0.80

Calls 2

loadMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected