-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce Auth controller extender (#7)
* feat: Add an extender to allow for post auth completion callbacks * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
ae9b322
commit ac8a28d
Showing
2 changed files
with
115 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/extend. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Extend\Extend; | ||
|
||
use Flarum\Extend\ExtenderInterface; | ||
use Flarum\Extension\Extension; | ||
use Flarum\Foundation\ContainerUtil; | ||
use FoF\Extend\Controllers\AbstractOAuthController; | ||
use Illuminate\Contracts\Container\Container; | ||
|
||
class OAuthController implements ExtenderInterface | ||
{ | ||
protected $afterOAuthSuccessCallbacks = []; | ||
|
||
/** | ||
* Register a callback to be executed after a successful OAuth login, but before the user is logged in to Flarum. | ||
* | ||
* @param callable|string $callback | ||
* | ||
* The callback can be a closure or an invokable class and should accept: | ||
* - $request: An instance of \Psr\Http\Message\ServerRequestInterface. | ||
* - $token: An instance of \League\OAuth2\Client\Token\AccessTokenInterface, representing the access token. | ||
* - $resourceOwner: An instance of \League\OAuth2\Client\Provider\ResourceOwnerInterface, representing the authenticated user's resource. | ||
* - $identification: A string identifying `fof/oauth` provider, e.g. `github. | ||
* | ||
* It should return either `void` if no further action is required from the callback, or `Psr\Http\Message\ResponseInterface`. | ||
* | ||
* @return $this | ||
*/ | ||
public function afterOAuthSuccess($callback) | ||
{ | ||
$this->afterOAuthSuccessCallbacks[] = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function extend(Container $container, Extension $extension = null) | ||
{ | ||
foreach ($this->afterOAuthSuccessCallbacks as $index => $callback) { | ||
$this->afterOAuthSuccessCallbacks[$index] = ContainerUtil::wrapCallback($callback, $container); | ||
} | ||
|
||
AbstractOAuthController::setAfterOAuthSuccessCallbacks($this->afterOAuthSuccessCallbacks); | ||
} | ||
} |