feat: add oauth group permission

This commit is contained in:
FoskyM 2023-10-13 20:30:09 +08:00
parent 3db1e1328c
commit fb3b2a6c6c
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
7 changed files with 27 additions and 2 deletions

BIN
js/dist/admin.js generated vendored

Binary file not shown.

BIN
js/dist/admin.js.map generated vendored

Binary file not shown.

View file

@ -3,5 +3,14 @@ import SettingsPage from './components/SettingsPage';
app.initializers.add('foskym/flarum-oauth-center', () => {
app.extensionData
.for('foskym-oauth-center')
.registerPage(SettingsPage);
.registerPage(SettingsPage)
.registerPermission(
{
icon: 'fas fa-user-friends',
label: app.translator.trans('foskym-oauth-center.admin.permission.use_oauth'),
permission: 'foskym-oauth-center.use-oauth',
},
'use-oauth',
95
);
});

View file

@ -1,5 +1,7 @@
foskym-oauth-center:
admin:
permission:
use_oauth: Use OAuth
page:
index: home
clients: Manage Clients

View file

@ -1,5 +1,7 @@
foskym-oauth-center:
admin:
permission:
use_oauth: 使用 OAuth 授权
page:
index: 首页
clients: 应用管理

View file

@ -4,6 +4,7 @@ namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController;
use Flarum\Http\RequestUtil;
use Flarum\User\Exception\NotAuthenticatedException;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
@ -16,7 +17,13 @@ class ShowClientController extends AbstractListController
protected function data(ServerRequestInterface $request, Document $document)
{
$client_id = Arr::get($request->getQueryParams(), 'client_id');
RequestUtil::getActor($request)->assertRegistered();
$actor = RequestUtil::getActor($request);
$actor->assertRegistered();
if (!$actor->hasPermission('foskym-oauth-center.use-oauth')) {
throw new NotAuthenticatedException();
}
$client = Client::where('client_id', $client_id)->get();

View file

@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
namespace FoskyM\OAuthCenter\Controllers;
use Flarum\User\Exception\NotAuthenticatedException;
use Flarum\User\User;
use Flarum\Http\RequestUtil;
use FoskyM\OAuthCenter\OAuth;
@ -33,6 +34,10 @@ class AuthorizeController implements RequestHandlerInterface
$actor = RequestUtil::getActor($request);
$actor->assertRegistered();
if (!$actor->hasPermission('foskym-oauth-center.use-oauth')) {
throw new NotAuthenticatedException();
}
$params = $request->getParsedBody();
$oauth = new OAuth($this->settings);