feat: add oauth group permission
This commit is contained in:
parent
3db1e1328c
commit
fb3b2a6c6c
7 changed files with 27 additions and 2 deletions
BIN
js/dist/admin.js
generated
vendored
BIN
js/dist/admin.js
generated
vendored
Binary file not shown.
BIN
js/dist/admin.js.map
generated
vendored
BIN
js/dist/admin.js.map
generated
vendored
Binary file not shown.
|
@ -3,5 +3,14 @@ import SettingsPage from './components/SettingsPage';
|
||||||
app.initializers.add('foskym/flarum-oauth-center', () => {
|
app.initializers.add('foskym/flarum-oauth-center', () => {
|
||||||
app.extensionData
|
app.extensionData
|
||||||
.for('foskym-oauth-center')
|
.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
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
foskym-oauth-center:
|
foskym-oauth-center:
|
||||||
admin:
|
admin:
|
||||||
|
permission:
|
||||||
|
use_oauth: Use OAuth
|
||||||
page:
|
page:
|
||||||
index: home
|
index: home
|
||||||
clients: Manage Clients
|
clients: Manage Clients
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
foskym-oauth-center:
|
foskym-oauth-center:
|
||||||
admin:
|
admin:
|
||||||
|
permission:
|
||||||
|
use_oauth: 使用 OAuth 授权
|
||||||
page:
|
page:
|
||||||
index: 首页
|
index: 首页
|
||||||
clients: 应用管理
|
clients: 应用管理
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace FoskyM\OAuthCenter\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\Controller\AbstractListController;
|
use Flarum\Api\Controller\AbstractListController;
|
||||||
use Flarum\Http\RequestUtil;
|
use Flarum\Http\RequestUtil;
|
||||||
|
use Flarum\User\Exception\NotAuthenticatedException;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
@ -16,7 +17,13 @@ class ShowClientController extends AbstractListController
|
||||||
protected function data(ServerRequestInterface $request, Document $document)
|
protected function data(ServerRequestInterface $request, Document $document)
|
||||||
{
|
{
|
||||||
$client_id = Arr::get($request->getQueryParams(), 'client_id');
|
$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();
|
$client = Client::where('client_id', $client_id)->get();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
namespace FoskyM\OAuthCenter\Controllers;
|
namespace FoskyM\OAuthCenter\Controllers;
|
||||||
|
use Flarum\User\Exception\NotAuthenticatedException;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
use Flarum\Http\RequestUtil;
|
use Flarum\Http\RequestUtil;
|
||||||
use FoskyM\OAuthCenter\OAuth;
|
use FoskyM\OAuthCenter\OAuth;
|
||||||
|
@ -33,6 +34,10 @@ class AuthorizeController implements RequestHandlerInterface
|
||||||
$actor = RequestUtil::getActor($request);
|
$actor = RequestUtil::getActor($request);
|
||||||
$actor->assertRegistered();
|
$actor->assertRegistered();
|
||||||
|
|
||||||
|
if (!$actor->hasPermission('foskym-oauth-center.use-oauth')) {
|
||||||
|
throw new NotAuthenticatedException();
|
||||||
|
}
|
||||||
|
|
||||||
$params = $request->getParsedBody();
|
$params = $request->getParsedBody();
|
||||||
|
|
||||||
$oauth = new OAuth($this->settings);
|
$oauth = new OAuth($this->settings);
|
||||||
|
|
Loading…
Reference in a new issue