Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d46859a4 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

feat: for SSO, use already saved KC uid

oidc_login should already saved the KC uid in the preference DB table
for loggedIn user. So, we don't need to retrieve the uid for each SSO
    requests.

issue: https://gitlab.e.foundation/e/infra/backlog/-/issues/4352
parent c69d8def
Loading
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class SSOService {

	public function migrateCredential(string $username, string $secret) : void {
		if($this->isNotCurrentUser($username)) {
			$this->getUserId($username);
			$this->setupUserId($username);
		}

		$this->deleteCredentials($username);
@@ -84,7 +84,7 @@ class SSOService {

	public function deleteCredentials(string $username) : void {
		if($this->isNotCurrentUser($username)) {
			$this->getUserId($username);
			$this->setupUserId($username);
		}

		$credentialIds = $this->getCredentialIds();
@@ -100,7 +100,7 @@ class SSOService {

	public function logout(string $username) : void {
		if($this->isNotCurrentUser($username)) {
			$this->getUserId($username);
			$this->setupUserId($username);
		}

		$url = $this->ssoConfig['admin_rest_api_url'] . self::USERS_ENDPOINT . '/' . $this->currentUserId . '/logout';
@@ -159,7 +159,19 @@ class SSOService {
		return $credentialEntry;
	}

	private function getUserId(string $username) : void {
	private function setupUserId(string $username) {
		$user = $this->userManager->get($username);
		$savedOIDCUid = $this->config->getUserValue($user->getUID(), 'oidc_login', 'oidc_uid');

		if ($savedOIDCUid !== null && trim($savedOIDCUid) !== '') {
			$this->currentUserId = $savedOIDCUid;
			return;
		}

		$this->retriveUserId($username);
	}

	private function retriveUserId(string $username) {
		$user = $this->userManager->get($username);
		if ($user === null) {
			throw new SSOAdminAPIException('Error: no user exists in cloud with username ' . $username);