Skip to content

Commit 281f43c

Browse files
authored
Merge pull request #3 from YesWiki/ynh-12-portal
repair sso login/logon for YunoHost 12
2 parents a326087 + 8604994 commit 281f43c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.php-cs-fixer.cache
12
vendor

actions/LoginAction__.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,30 @@ public function run()
1515
$incomingUrl = (empty($_SERVER['HTTPS']) ? 'http' : 'https').
1616
"://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
1717
$encodedUrl = base64_encode($incomingUrl);
18+
if (!file_exists('files/yunohost_version')) {
19+
exec('dpkg-query --show --showformat=\'${Version}\' yunohost > files/yunohost_version');
20+
}
21+
$yunohostVersion = file_get_contents('files/yunohost_version');
22+
$majorYunohostVersion = explode('.', $yunohostVersion)[0] ?? '';
23+
// we default on current stable Yunohost's version urls
24+
$loginUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/login?r='.$encodedUrl;
25+
$logoutUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/portalapi/logout?referer_redirect';
26+
;
27+
if ($majorYunohostVersion == '11') {
28+
// backward compatibility
29+
$loginUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?r='.$encodedUrl;
30+
$logoutUrl = 'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?action=logout&r='.$encodedUrl;
31+
}
32+
1833
$authController = $this->getService(AuthController::class);
1934
if ($authController->getLoggedUser()) {
2035
$this->output = preg_replace(
2136
'~"https?://.*action=logout"~Ui',
22-
'https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?action=logout&r='.$encodedUrl,
37+
$logoutUrl,
2338
$this->output
2439
);
2540
} else {
26-
$this->output = '<a href="https://'.$this->params->get('yunohost_sso_domain').'/yunohost/sso/?r='.$encodedUrl.'" class="btn btn-default btn->
41+
$this->output = '<a href="'.$loginUrl.'" class="btn btn-default btn->
2742
<i class="glyphicon glyphicon-user"></i> '._t('LOGIN_LOGIN').'</a>';
2843
}
2944
}

0 commit comments

Comments
 (0)