Skip to content

Commit 2315fff

Browse files
committed
refactor: modernize session management and token validation
- Extract bearer token parsing, OIDC config reading, validator instantiation, NC provider validation, and user resolution into dedicated private methods to reduce cognitive complexity of getCurrentUserId() - Replace the first-match-wins loop with findUniqueTokenMatch(), which requires unambiguous validation across all providers: a token accepted by more than one (provider, userId) pair is rejected with a warning - Add countUsers() via a direct COUNT(*) query instead of fetching all UIDs into memory - Introduce SESSION_USER_DATA, SESSION_PASSWORD_CONFIRM, and PASSWORD_CONFIRM_TTL constants to avoid magic strings/numbers - Fix first-login setup: move getUserFolder() inside the try/catch so a NotFoundException from storage setup no longer aborts login - Keep $existingUser null when a user is freshly created via getOrCreate() so provisionUser() is not passed the wrong identity when UNIQUE_UID or PROVIDER_BASED_ID cause the stored ID to differ from the token sub - Add doc blocks to all new private methods, with extended descriptions for methods that change observable backend behaviour Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent 63fc774 commit 2315fff

2 files changed

Lines changed: 478 additions & 201 deletions

File tree

lib/Db/UserMapper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,22 @@ public function getOrCreate(int $providerId, string $sub, bool $id4me = false):
169169
$user->setUserId($userId);
170170
return $this->insert($user);
171171
}
172+
173+
/**
174+
* Count the total number of users provisioned by the OIDC backend.
175+
*
176+
* @return int the number of rows in the user_oidc table
177+
*/
178+
public function countUsers(): int {
179+
$qb = $this->db->getQueryBuilder();
180+
181+
$qb->selectAlias($qb->func()->count('*'), 'user_count')
182+
->from($this->getTableName());
183+
184+
$result = $qb->executeQuery();
185+
$count = $result->fetchOne();
186+
$result->closeCursor();
187+
188+
return (int)$count;
189+
}
172190
}

0 commit comments

Comments
 (0)