nextcloud/impersonate

Add: Emitter event so that other apps know about impersonate

the-djmaze opened this issue · 3 comments

My app has a login system and users have an issue when impersonating, the login doesn't logout.
the-djmaze/snappymail#561

I've tried to create a workaround but that has issues with storing data in session (NC25 might solve this).
nextcloud/server#34935

However, i think it would be better to have an event to listen to for a much better approach.
Can you add an emit() like:

$this->userSession->setUser($user);

		$this->userSession->getManager()->emit('\OC\User', 'impersonate', [$currentUser, $user])
		$this->userSession->setUser($user);

$this->userSession->setUser($user);

		$this->userSession->getManager()->emit('\OC\User', 'impersonate', [$this->userSession->getUser(), $user])
		$this->userSession->setUser($user);

should be a typed event nowadays, but generally a PR implemeted this would be accepted.

As a workaround, perhaps checking whether $session->get('oldUserId') (from OCP\ISession) is set could already help.

As a workaround, perhaps checking whether $session->get('oldUserId') (from OCP\ISession) is set could already help.

That has an issue.

  1. Login Nextcloud
  2. SnappyMail login IMAP
  3. Impersonate
  4. if (oldUserId) SnappyMail->logout()
  5. Login SnappyMail manually
  6. if (oldUserId) SnappyMail->logout()

Step 5 - 6 will then be a repeat, so there must be some kind of permanent check.

  1. SnappyMail keeps track of current IUser (issue with save to session in NC24)
  2. Or just listen to events (also not the best, but doable)

WIP at #180