8000 master logout event by ArtificialOwl · Pull Request #135 · nextcloud/globalsiteselector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

master logout event #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions lib/Controller/MasterController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* @author Maxence Lange <maxence@artificial-owl.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
Expand All @@ -21,18 +24,17 @@
*
*/


namespace OCA\GlobalSiteSelector\Controller;

use OCA\GlobalSiteSelector\AppInfo\Application;
use OCA\GlobalSiteSelector\Events\GlobalScaleMasterLogoutEvent;
use OCA\GlobalSiteSelector\GlobalSiteSelector;
use OCA\GlobalSiteSelector\Master;
use OCA\GlobalSiteSelector\Vendor\Firebase\JWT\JWT;
use OCA\GlobalSiteSelector\Vendor\Firebase\JWT\Key;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\OCSController;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;

Expand All @@ -44,28 +46,16 @@
* @package OCA\GlobalSiteSelector\Controller
*/
class MasterController extends OCSController {
private IURLGenerator $urlGenerator;
private ISession $session;
private GlobalSiteSelector $gss;
private Master $master;
private LoggerInterface $logger;

public function __construct(
$appName,
string $appName,
IRequest $request,
IURLGenerator $urlGenerator,
ISession $session,
GlobalSiteSelector $globalSiteSelector,
Master $master,
LoggerInterface $logger
private IURLGenerator $urlGenerator,
private IEventDispatcher $eventDispatcher,
private GlobalSiteSelector $gss,
private LoggerInterface $logger
) {
parent::__construct($appName, $request);

$this->urlGenerator = $urlGenerator;
$this->session = $session;
$this->gss = $globalSiteSelector;
$this->master = $master;
$this->logger = $logger;
}

/**
Expand All @@ -82,20 +72,23 @@ public function autoLogout(?string $jwt) {
if ($jwt !== null) {
$key = $this->gss->getJwtKey();
$decoded = (array)JWT::decode($jwt, new Key($key, Application::JWT_ALGORITHM));
$idp = $decoded['saml.idp'] ?? null;

$logoutUrl = $this->urlGenerator->linkToRoute('user_saml.SAML.singleLogoutService');
if (!empty($logoutUrl)) {
$token = [
'logout' => 'logout',
'idp' => $idp,
'exp' => time() + 300, // expires after 5 minutes
];

$jwt = JWT::encode($token, $this->gss->getJwtKey(), Application::JWT_ALGORITHM);
$event = new GlobalScaleMasterLogoutEvent();
$event->setIdp($decoded['saml.idp'] ?? '');
$this->eventDispatcher->dispatchTyped($event);

return new RedirectResponse($logoutUrl . '?jwt=' . $jwt);
}
// $logoutUrl = $this->urlGenerator->linkToRoute('user_saml.SAML.singleLogoutService');
// if (!empty($logoutUrl)) {
// $token = [
// 'logout' => 'logout',
// 'idp' => $idp,
// 'exp' => time() + 300, // expires after 5 minutes
// ];
//
// $jwt = JWT::encode($token, $this->gss->getJwtKey(), Application::JWT_ALGORITHM);
//
// return new RedirectResponse($logoutUrl . '?jwt=' . $jwt);
// }
}
} catch (\Exception $e) {
$this->logger->warning('remote logout request failed', ['exception' => $e]);
Expand Down
43 changes: 43 additions & 0 deletions lib/Events/GlobalScaleMasterLogoutEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\GlobalSiteSelector\Events;

use OCP\EventDispatcher\Event;

class GlobalScaleMasterLogoutEvent extends Event {
private string $idp = '';

public function __construct() {
parent::__construct();
}

public function setIdp(string $idp): void {
$this->idp = $idp;
}

public function getIdp(): string {
return $this->idp;
}
}
0