Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
[upg] v0.1.0-beta.14
Browse files Browse the repository at this point in the history
  • Loading branch information
tituspijean committed Oct 24, 2020
1 parent 49b5c0a commit 5c0570b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"source": "https://github.com/tituspijean/flarum-ext-auth-ssowat"
},
"require": {
"flarum/core": ">=0.1.0-beta.12 <0.1.0-beta.14"
"flarum/core": "^0.1.0-beta.14"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 8 additions & 4 deletions src/Middleware/SSOwatMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TitusPiJean\Flarum\Auth\SSOwat\Middleware;

use Illuminate\Support\Arr;
use Flarum\Foundation\Application;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -12,6 +13,7 @@
use Flarum\Http\SessionAuthenticator;
use Flarum\Http\Rememberer;
use Flarum\User\Event\LoggedOut;
use Flarum\Http\UrlGenerator;
use Flarum\User\Exception\PermissionDeniedException;
use Flarum\Settings\SettingsRepositoryInterface;

Expand All @@ -26,12 +28,14 @@ class SSOwatMiddleware implements MiddlewareInterface
*/
public function __construct(
Application $app,
UrlGenerator $url,
Dispatcher $events,
SessionAuthenticator $authenticator,
Rememberer $rememberer,
SettingsRepositoryInterface $settings
) {
$this->app = $app;
$this->url = $url;
$this->events = $events;
$this->settings = $settings;
$this->authenticator = $authenticator;
Expand All @@ -40,7 +44,7 @@ public function __construct(

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// Retrieve the session and check if the user logged in with SSOwat
// Retrieve the session and check if the user is logged in with SSOwat
$session=$request->getAttribute('session');
$ssowatUser=$session->get('ssowatUser');
if ($ssowatUser) {
Expand All @@ -54,21 +58,21 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// If not, do the same steps as Flarum's LogOutController
// Prepare redirection to SSOwat
$ssowat = $this->settings->get('tituspijean-auth-ssowat.domain');
$url = array_get($request->getQueryParams(), 'return', $this->app->url());
$url = Arr::get($request->getQueryParams(), 'return', $this->url->to('forum'));
$r = base64_encode($url);
//$r = base64_encode("https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$urlredirect = "https://" . $ssowat . "/yunohost/sso/?action=logout&r=" . $r;
$response = new RedirectResponse($urlredirect);
//Log out
$this->authenticator->logOut($session);
$actor->accessTokens()->delete();
$this->events->fire(new LoggedOut($actor));
$this->events->dispatch(new LoggedOut($actor));
$this->rememberer->forget($response);
// Throw an error if JSON was requested, or redirect to logout
if (str_contains($request->getHeaderLine('content-type'), 'json')) {
throw new PermissionDeniedException("You have been logged out from YunoHost.", 401, null);
} else {
return new RedirectResponse($this->app->url()."/logout?token=".$session->get('csrf_token'));
return new RedirectResponse($this->url->to('forum')->route('logout', ['token' => $session->get('csrf_token')]));
}
}
}
Expand Down

0 comments on commit 5c0570b

Please sign in to comment.