Skip to content

Commit e626d35

Browse files
committed
Merge #27 [V33] Redirect after access denied error
2 parents 568e605 + 8c19fdc commit e626d35

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/Controller/LoginController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ public function code(string $state = '', string $code = '', string $scope = '',
335335
$this->logger->debug('Code login with core: ' . $code . ' and state: ' . $state);
336336

337337
if ($error !== '') {
338+
if (!$this->isMobileDevice()) {
339+
$cancelRedirectUrl = $this->config->getSystemValue('user_oidc.cancel_redirect_url', 'https://cloud.telekom-dienste.de/');
340+
return new RedirectResponse($cancelRedirectUrl);
341+
}
342+
338343
$this->logger->warning('Code login error', ['error' => $error, 'error_description' => $error_description]);
339344
if ($this->isDebugModeEnabled()) {
340345
return new JSONResponse([
@@ -944,4 +949,20 @@ private function toCodeChallenge(string $data): string {
944949
$s = str_replace('/', '_', $s); // 63rd char of encoding
945950
return $s;
946951
}
952+
953+
private function isMobileDevice(): bool {
954+
$mobileKeywords = $this->config->getSystemValue('user_oidc.mobile_keywords', ['Android', 'iPhone', 'iPad', 'iPod', 'Windows Phone', 'Mobile', 'webOS', 'BlackBerry', 'Opera Mini', 'IEMobile']);
955+
956+
if (!isset($_SERVER['HTTP_USER_AGENT'])) {
957+
return false; // if no user-agent is set, assume desktop
958+
}
959+
960+
foreach ($mobileKeywords as $keyword) {
961+
if (stripos($_SERVER['HTTP_USER_AGENT'], $keyword) !== false) {
962+
return true; // device is mobile
963+
}
964+
}
965+
966+
return false; // device is desktop
967+
}
947968
}

0 commit comments

Comments
 (0)