Skip to content

Commit e07a953

Browse files
committed
Merge #11 modified code login session value handling
2 parents e2417e3 + 3e46643 commit e07a953

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/Controller/LoginController.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,21 @@ public function login(int $providerId, string $redirectUrl = null) {
222222
return $this->buildErrorTemplateResponse($message, Http::STATUS_NOT_FOUND, ['provider_not_found' => $providerId]);
223223
}
224224

225-
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
226-
$this->session->set(self::STATE, $state);
227-
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
225+
// check if oidc state is present in session data
226+
if ($this->session->exists(self::STATE)) {
227+
$state = $this->session->get(self::STATE);
228+
$nonce = $this->session->get(self::NONCE);
229+
} else {
230+
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
231+
$this->session->set(self::STATE, $state);
232+
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
233+
234+
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
235+
$this->session->set(self::NONCE, $nonce);
228236

229-
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
230-
$this->session->set(self::NONCE, $nonce);
237+
$this->session->set(self::PROVIDERID, $providerId);
238+
}
231239

232-
$this->session->set(self::PROVIDERID, $providerId);
233240
$this->session->close();
234241

235242
// get attribute mapping settings
@@ -502,6 +509,11 @@ public function code(string $state = '', string $code = '', string $scope = '',
502509
$this->userSession->createSessionToken($this->request, $user->getUID(), $user->getUID());
503510
$this->userSession->createRememberMeToken($user);
504511

512+
// remove code login session values
513+
$this->session->remove(self::STATE);
514+
$this->session->remove(self::REDIRECT_AFTER_LOGIN);
515+
$this->session->remove(self::NONCE);
516+
505517
// Set last password confirm to the future as we don't have passwords to confirm against with SSO
506518
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
507519

0 commit comments

Comments
 (0)