Skip to content

Commit

Permalink
experimental: in the user backend, return a user id if it was set in …
Browse files Browse the repository at this point in the history
…the session during the login flow

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 13, 2025
1 parent bb583fe commit 67fd4f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LoginController extends BaseOidcController {
private const REDIRECT_AFTER_LOGIN = 'oidc.redirect';
private const ID_TOKEN = 'oidc.id_token';
private const CODE_VERIFIER = 'oidc.code_verifier';
public const USER_ID = 'oidc.user_id';

public function __construct(
IRequest $request,
Expand Down Expand Up @@ -501,6 +502,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
}

$this->session->set(self::ID_TOKEN, $idTokenRaw);
$this->session->set(self::USER_ID, $user->getUID());

$this->logger->debug('Logging user in');

Expand All @@ -509,6 +511,8 @@ public function code(string $state = '', string $code = '', string $scope = '',
$this->userSession->completeLogin($user, ['loginName' => $user->getUID(), 'password' => '']);
$this->userSession->createSessionToken($this->request, $user->getUID(), $user->getUID());
$this->userSession->createRememberMeToken($user);
// TODO delete that
// $this->eventDispatcher->dispatchTyped(new BeforeUserLoggedInEvent($user->getUID(), null, \OC::$server->get(Backend::class)));
}

// store all token information for potential token exchange requests
Expand Down
12 changes: 12 additions & 0 deletions lib/User/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ private function formatUserData(int $providerId, array $attributes): array {
* @since 6.0.0
*/
public function getCurrentUserId(): string {
// experimental: check if we are at the end of the login flow
$this->logger->warning('getCurrentUserId');
if ($this->session instanceof ISession) {
$this->logger->warning('there is a session');
$userId = $this->session->get(LoginController::USER_ID);
if ($userId !== '' && $userId !== null) {
$this->logger->warning('there is a user ID', ['uid' => $userId]);
return $userId;
}
}
$this->logger->warning('in getCurrentUserId, no user ID was found, checking request headers');

$providers = $this->providerMapper->getProviders();
if (count($providers) === 0) {
$this->logger->debug('no OIDC providers');
Expand Down

0 comments on commit 67fd4f1

Please sign in to comment.