-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update to support new AbstractController
- Loading branch information
Showing
5 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace FoF\OAuth\Api; | ||
|
||
use Flarum\Api\Serializer\CurrentUserSerializer; | ||
use Flarum\User\User; | ||
use FoF\Extend\Controllers\AbstractOAuthController; | ||
use Illuminate\Contracts\Cache\Store as Cache; | ||
|
||
class CurrentUserAttributes | ||
{ | ||
/** | ||
* @var Cache | ||
*/ | ||
protected $cache; | ||
|
||
public function __construct(Cache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
|
||
public function __invoke(CurrentUserSerializer $serializer, User $user, array $attributes): array | ||
{ | ||
$session = $serializer->getRequest()->getAttribute('session'); | ||
|
||
$attributes['loginProvider'] = $this->cache->get(AbstractOAuthController::SESSION_OAUTH2PROVIDER . '_' . $session->getId()); | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace FoF\OAuth\Listeners; | ||
|
||
use Flarum\Http\RequestUtil; | ||
use Flarum\User\Event\LoggedOut; | ||
use FoF\Extend\Controllers\AbstractOAuthController; | ||
use Illuminate\Contracts\Cache\Store as Cache; | ||
use Illuminate\Session\Store as Session; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
class HandleLogout | ||
{ | ||
/** | ||
* @var Cache | ||
*/ | ||
protected $cache; | ||
|
||
public function __construct(Cache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
|
||
public function handle(LoggedOut $event) | ||
{ | ||
$user = $event->user; | ||
|
||
/** @var ServerRequestInterface|null $request */ | ||
$request = resolve('fof-oauth-request'); | ||
|
||
if ($request) { | ||
$requestUser = RequestUtil::getActor($request); | ||
|
||
if ($requestUser->id === $user->id) { | ||
/** @var Session $session */ | ||
$session = $request->getAttribute('session'); | ||
|
||
$this->cache->forget(AbstractOAuthController::SESSION_OAUTH2PROVIDER . '_' . $session->getId()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace FoF\OAuth\Middleware; | ||
|
||
use Illuminate\Contracts\Container\Container; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class ServerRequestMiddleware implements MiddlewareInterface | ||
{ | ||
protected $container; | ||
|
||
public function __construct(Container $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$this->container->instance('fof-oauth-request', $request); | ||
|
||
return $handler->handle($request); | ||
} | ||
} |