feat: oauth token(TokenController.php)
This commit is contained in:
parent
418ee02bb4
commit
940a989fb4
1 changed files with 40 additions and 0 deletions
40
src/Controllers/TokenController.php
Normal file
40
src/Controllers/TokenController.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of foskym/flarum-oauth-center.
|
||||
*
|
||||
* Copyright (c) 2023 FoskyM.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.md
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace FoskyM\OAuthCenter\Controllers;
|
||||
use Flarum\User\User;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use FoskyM\OAuthCenter\OAuth;
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\Group\Group;
|
||||
|
||||
class TokenController implements RequestHandlerInterface
|
||||
{
|
||||
protected $settings;
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$oauth = new OAuth($this->settings);
|
||||
$server = $oauth->server();
|
||||
|
||||
$body = $server->handleTokenRequest($oauth->request()::createFromGlobals())
|
||||
->getResponseBody();
|
||||
return new JsonResponse(json_decode($body, true));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue