From 7a82b15c49c0c25bbff475d70bb8062594d4980c Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 18:18:43 +0800 Subject: [PATCH] fix: get client info --- extend.php | 5 +++ js/dist/forum.js | Bin 3541 -> 4090 bytes js/dist/forum.js.map | Bin 12321 -> 13659 bytes .../forum/components/oauth/AuthorizePage.js | 23 +++++++++++- src/Api/Controller/ShowClientController.php | 10 ++--- src/Api/Serializer/ClientPublicSerializer.php | 35 ++++++++++++++++++ 6 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/Api/Serializer/ClientPublicSerializer.php diff --git a/extend.php b/extend.php index cebf87a..2d24d6b 100644 --- a/extend.php +++ b/extend.php @@ -35,5 +35,10 @@ return [ ->patch('/oauth-clients/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), + (new Extend\Settings) + ->serializeToForum('foskym-oauth-center.allow_implicit', 'foskym-oauth-center.allow_implicit', 'boolval') + ->serializeToForum('foskym-oauth-center.enforce_state', 'foskym-oauth-center.enforce_state', 'boolval') + ->serializeToForum('foskym-oauth-center.require_exact_redirect_uri', 'foskym-oauth-center.require_exact_redirect_uri', 'boolval'), + (new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class), ]; diff --git a/js/dist/forum.js b/js/dist/forum.js index 7564cab6f04bfac660dbd72f6ada1a5e1cd14261..2422d75c017c9af68f12a51062aefe48d9701d4a 100644 GIT binary patch delta 1204 zcmbtTJ#QOF5XDCP5E%z{K}$+xM5lux?3$|+4FnKC=3*Fu3#W)&IF%3+M`|c7blj!q z_9zh)!6?5V!q%>gRH+ideadvM61DLkunnY3;be}cKCH??n!(-9&U^Fb&Hldl_tFpZ z438FS>nMj&9Y;dqNN&|RNEG20!;V4TkI*xo(jE#M7>?42m6he}6QnsBFD@841f6yP zqgD*{<(k|ETgOfF^DiGWhVIY&b@x2~k$cI?MHAXUb3FcseZb1;uVn4S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=am%Hy diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index 467eeb8..10ac76b 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -21,8 +21,22 @@ export default class AuthorizePage extends IndexPage { } else { this.params = params; app.store.find('oauth-clients', params.client_id).then(client => { - this.client = client; - console.log(client); + if (client.length === 0) { + m.route.set('/'); + } else { + this.client = client[0]; + const uris = client.redirect_uri.split(' '); + console.log(uris); + if (app.forum.attribute('foskym-oauth-center.require_exact_redirect_uri') && uris.indexOf(params.redirect_uri) == -1) { + m.route.set('/'); + } + if (app.forum.attribute('foskym-oauth-center.allow_implicit') && params.response_type == 'token') { + m.route.set('/'); + } + if (app.forum.attribute('foskym-oauth-center.enforce_state') && params.enforce_state == null) { + m.route.set('/'); + } + } }); } } @@ -32,6 +46,11 @@ export default class AuthorizePage extends IndexPage { app.setTitleCount(0); } view() { + if (!this.client) { + return ''; + } + app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize') + ' ' + this.client.client_name)); + app.setTitleCount(0); return (
diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 2b662d7..5a64375 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -8,21 +8,17 @@ use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; -use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; +use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer; class ShowClientController extends AbstractListController { - public $serializer = ClientSerializer::class; + public $serializer = ClientPublicSerializer::class; protected function data(ServerRequestInterface $request, Document $document) { $client_id = Arr::get($request->getQueryParams(), 'client_id'); RequestUtil::getActor($request)->assertRegistered(); - $client = Client::whereOrFail('client_id', $client_id); - - if (isset($client->client_secret)) { - $client->client_secret = ''; - } + $client = Client::where('client_id', $client_id)->get(); return $client; diff --git a/src/Api/Serializer/ClientPublicSerializer.php b/src/Api/Serializer/ClientPublicSerializer.php new file mode 100644 index 0000000..660fd63 --- /dev/null +++ b/src/Api/Serializer/ClientPublicSerializer.php @@ -0,0 +1,35 @@ + $model->id, + "client_id" => $model->client_id, + "redirect_uri" => $model->redirect_uri, + "grant_types" => $model->grant_types, + "scope" => $model->scope, + "client_name" => $model->client_name, + "client_icon" => $model->client_icon, + "client_desc" => $model->client_desc, + "client_home" => $model->client_home + ]; + } +}