Skip to content

Commit 95c0352

Browse files
committed
respect redirect_url
This makes OIDC work with the login flow Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent c5910f7 commit 95c0352

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/AppInfo/Application.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCA\UserOIDC\User\Backend;
3030
use OCP\AppFramework\App;
3131
use OCP\IL10N;
32+
use OCP\IRequest;
3233
use OCP\IURLGenerator;
3334
use OCP\IUserManager;
3435
use OCP\IUserSession;
@@ -63,10 +64,23 @@ public function register() {
6364
/** @var IL10N $l10n */
6465
$l10n = $this->getContainer()->query(IL10N::class);
6566

67+
/** @var IRequest $request */
68+
$request = $this->getContainer()->query(IRequest::class);
69+
$requestParams = $request->getParams();
70+
71+
$redirectUrl = '';
72+
if(isset($requestParams['redirect_url'])) {
73+
$redirectUrl = $requestParams['redirect_url'];
74+
}
75+
6676
foreach ($providers as $provider) {
6777
\OC_App::registerLogIn([
6878
'name' => $l10n->t('Login with %1s', [$provider->getIdentifier()]),
69-
'href' => $urlGenerator->linkToRoute(self::APP_ID . '.login.login', ['providerId' => $provider->getId()]),
79+
'href' => $urlGenerator->linkToRoute(self::APP_ID . '.login.login',
80+
[
81+
'providerId' => $provider->getId(),
82+
'redirectUrl' => $redirectUrl,
83+
]),
7084
]);
7185
}
7286

lib/Controller/LoginController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class LoginController extends Controller {
4848
private const STATE = 'oidc.state';
4949
private const NONCE = 'oidc.nonce';
5050
private const PROVIDERID = 'oidc.providerid';
51+
private const REDIRECTURL = 'oidc.redirecturl';
5152

5253
/** @var ISecureRandom */
5354
private $random;
@@ -112,7 +113,7 @@ public function __construct(
112113
* @NoCSRFRequired
113114
* @UseSession
114115
*/
115-
public function login(int $providerId) {
116+
public function login(int $providerId, string $redirectUrl = '') {
116117
$this->logger->debug('Initiating login for provider with id: ' . $providerId);
117118

118119
//TODO: handle exceptions
@@ -125,6 +126,9 @@ public function login(int $providerId) {
125126
$this->session->set(self::NONCE, $nonce);
126127

127128
$this->session->set(self::PROVIDERID, $providerId);
129+
130+
$this->session->set(self::REDIRECTURL, $redirectUrl);
131+
128132
$this->session->close();
129133

130134
$data = [
@@ -252,9 +256,12 @@ public function code($state = '', $code = '', $scope = '') {
252256

253257
$this->logger->debug('Redirecting user');
254258

255-
// TODO: user proper redirect url
259+
$redirectUrl = $this->session->get(self::REDIRECTURL);
260+
if ($redirectUrl === '') {
261+
$redirectUrl = \OC_Util::getDefaultPageUrl();
262+
}
256263

257-
return new RedirectResponse(\OC_Util::getDefaultPageUrl());
264+
return new RedirectResponse($redirectUrl);
258265
}
259266

260267
private function obtainDiscovery(string $url) {

0 commit comments

Comments
 (0)