feat(admin): list clients api
This commit is contained in:
parent
6fc62fc269
commit
5a8ea7f751
4 changed files with 90 additions and 7 deletions
|
@ -1,6 +1,17 @@
|
|||
import app from 'flarum/admin/app';
|
||||
import Page from 'flarum/common/components/Page';
|
||||
|
||||
export default class ClientsPage extends Page {
|
||||
settingName = 'collapsible-posts.reasons';
|
||||
translationPrefix = 'foskym-oauth-center.admin.clients.';
|
||||
oninit(vnode) {
|
||||
super.oninit(vnode);
|
||||
|
||||
app.store.find('clients').then(() => {
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
|
||||
view() {
|
||||
return (
|
||||
<div>
|
||||
|
|
|
@ -9,6 +9,16 @@ foskym-oauth-center:
|
|||
allow_implicit: 允许隐式授权(response_type=token)
|
||||
enforce_state: 强制状态验证(state 参数)
|
||||
require_exact_redirect_uri: 需要精确的重定向 URI
|
||||
clients:
|
||||
client_id: 应用 ID
|
||||
client_secret: 应用密钥
|
||||
redirect_uri: 回调地址(多地址请用空格分割)
|
||||
grant_types: 授权类型(可空)
|
||||
scope: 权限(可空)
|
||||
name: 应用名称(可空)
|
||||
description: 应用描述(可空)
|
||||
icon: 应用图标地址(可空 可使用fontawesome图标)
|
||||
home: 主页地址(可空)
|
||||
|
||||
forum:
|
||||
page:
|
||||
|
|
25
src/Api/Controller/ListClientController.php
Normal file
25
src/Api/Controller/ListClientController.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace FoskyM\OAuthCenter\Api\Controller;
|
||||
|
||||
use Flarum\Api\Controller\AbstractListController;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
use FoskyM\OAuthCenter\Models\Client;
|
||||
use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer;
|
||||
|
||||
class ListClientController extends AbstractListController
|
||||
{
|
||||
public $serializer = ClientSerializer::class;
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
if (!$actor->isAdmin()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Client::get();
|
||||
}
|
||||
}
|
37
src/Api/Serializer/ClientSerializer.php
Normal file
37
src/Api/Serializer/ClientSerializer.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace FoskyM\OAuthCenter\Api\Serializer;
|
||||
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
use FoskyM\OAuthCenter\Models\Client;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ClientSerializer extends AbstractSerializer
|
||||
{
|
||||
protected $type = 'oauth-clients';
|
||||
|
||||
protected function getDefaultAttributes($model)
|
||||
{
|
||||
if (!($model instanceof Client)) {
|
||||
throw new InvalidArgumentException(
|
||||
get_class($this) . ' can only serialize instances of ' . Client::class
|
||||
);
|
||||
}
|
||||
|
||||
// See https://docs.flarum.org/extend/api.html#serializers for more information.
|
||||
|
||||
return [
|
||||
"id" => $model->id,
|
||||
"client_id" => $model->client_id,
|
||||
"client_secret" => $model->client_secret,
|
||||
"redirect_uri" => $model->redirect_uri,
|
||||
"grant_types" => $model->grant_types,
|
||||
"scope" => $model->scope,
|
||||
"user_id" => $model->user_id,
|
||||
"client_name" => $model->client_name,
|
||||
"client_icon" => $model->client_icon,
|
||||
"client_desc" => $model->client_desc,
|
||||
"client_home" => $model->client_home
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue