From 7777628c8d22456a61af290aec7cbca46b14835c Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sat, 30 Sep 2023 09:55:35 +0800 Subject: [PATCH 01/35] feat(admin): clients page --- extend.php | 2 +- js/dist/admin.js | Bin 7015 -> 8327 bytes js/dist/admin.js.map | Bin 20632 -> 25169 bytes js/src/admin/pages/ClientsPage.js | 90 ++++++++++++++++++++++++++++-- less/admin.less | 29 ++++++++++ locale/zh-Hans.yml | 9 +-- 6 files changed, 121 insertions(+), 9 deletions(-) diff --git a/extend.php b/extend.php index c8f1edd..bad30c4 100644 --- a/extend.php +++ b/extend.php @@ -28,7 +28,7 @@ return [ (new Extend\Routes('forum')) ->post('/oauth/authorize', 'oauth.authorize.post', Controllers\AuthorizeController::class), (new Extend\Routes('api')) - ->get('/oauth/clients', 'oauth.clients.list', Api\Controller\ListClientController::class), + ->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class), (new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class), ]; diff --git a/js/dist/admin.js b/js/dist/admin.js index 47a216f0b03a994c05c3c66bcdb4dd3fc1aa9845..589a21ae64ba68aee1b50010ef57e7c5ecd50726 100644 GIT binary patch delta 1707 zcma)7OK%)S5Z2i1SB!9sABk;*)}sJD@p$3~7_#dj**L_6#19g}Yqc`%ncmqZGu=y1 z?_#rFZIF=Qf{4=MNW__30RI3ua^L_Lj$DzraDX2`&0`;d9N3jg)7>@IUw!pe&F^cU z6uvppcakD$5~CrAtO=H-wp!|&Qs??Ek0%Gsa*a8Xa+Ve9Eg(#WMXElZ zSXE#3pU^_}p#Ln`U;7uqW-<$4mojI--pXXb)-%t5{W25z{21H6V*Av<)1v|rQyL~| zqEKxQ{BhEYF}OxP0a{OiKB4&FxK=;@Xz(RXy9DqqXyUu!yV@+ZmjR%x(9kMV;=7^c z6XwZEo~o}$=4NQAWb4biZQH!q<5Z-_zm41((7fZlv7h?2y!vHucFy5Jm9r?fa|Jh` zY!`bZWk!8JH1~h__+rd*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=tc*PaQtv7mV)shXpKXa=@MD7u;Wkga+tP%r$%hhj4>o33F!)Rxp4z zU;@D^oCdh+Yhg5jK80Jqir^6n0aqXdu7X=wAiHoQe&H^T@aLuGTQI&o~OoVgF83m0te$K07SXU;v}zc#&j*YxS6z2*Lf z#G{Vqt=6Oz35W#stB!mY0YD(#WKvjkp0vysMllbZXj2SLDCBMX5s`tyo+60#T{Xo) z+*e3f0!jlUxDpql`m=9%ByQ?K!~rsO6b^tR$`YU~A9BnQ%YZI!NnN-+TttgN(DDfI ziv^}J^#fZJCCo4J9j7D_HmobsJExU!P;E(v-!setN{VQBjG(9t4MVY{H24C#*Wd1+ z@j9JmQWDP}j%ewh36$}yN0LOKcIgFbVY@P}U;BrfH!S_d-?K92A@Ic1ilwS}D5qf4 ztksMPv)*^r9qFkxEvrhTxPoT1xh!s^P3)M>s-q5e^)~OIPIN`1H6^kD*(ix;2c?$+ zJc?tnFd4CnfJ-@}?WUI-BTRdP!7Ol@5JFw)A6~GdBEFafcIJSy4xUYn{ZOCbq?63DyeZE7S+w(HReO`(MoPIWharFzXU9 zmgI5bG`N*B@F_hNu$ybBp9VT_o{!{z0hj**{tAQ+c8y-fw%Hilc9Cbz(!anWdk;^) zge^zrSf*EuvFeK{eg*G0kj!Fy7YA#-V$N7H1!)=scgzuKzEjt-6O5%UWXV&pAZ{uB zzGu31TZvVG)!gyVo)12KIMjB0ap*?BK1}-bOH64seo6lxYtwJlGu^ly)G~6_Kat-k z7u-hu*64VnRB%T|MhEWA4Ls4`BDOvWw_PcP=FrO+NUjzOvlA51lXKUPUnHX)E$d}> eO@Caib#JbD=*2kunJY diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index fd464c3..594f0a1 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -1,22 +1,104 @@ import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; - +import AdminPage from 'flarum/admin/components/AdminPage'; +import Button from 'flarum/common/components/Button'; +import Client from "../../common/models/Client"; export default class ClientsPage extends Page { settingName = 'collapsible-posts.reasons'; translationPrefix = 'foskym-oauth-center.admin.clients.'; + clients = []; oninit(vnode) { super.oninit(vnode); - app.store.find('oauth/clients').then(() => { + this.fields = [ + 'client_id', + 'client_secret', + 'redirect_uri', + 'grant_types', + 'scope', + 'client_name', + 'client_desc', + 'client_icon', + 'client_home' + ]; + + app.store.find('oauth-clients').then(r => { + this.clients = r; + this.fields.map(key => console.log(this.clients[0][key])) m.redraw(); }); } view() { return ( -
-

Clients Page

+
+ { + m('.Form-group', [ + m('table', [ + m('thead', m('tr', [ + this.fields.map(key => m('th', app.translator.trans(this.translationPrefix + key))), + m('th'), + ])), + m('tbody', [ + this.clients.map((client, index) => m('tr', [ + this.fields.map(key => + m('td', m('input.FormControl', { + type: 'text', + value: client[key]() || '', + onchange: (event) => { + this.saveClientInfo(client.id(), key, event.target.value); + }, + })) + ), + m('td', Button.component({ + className: 'Button Button--icon', + icon: 'fas fa-times', + onclick: () => { + this.clients.splice(index, 1); + + // this.setting(settingName)(JSON.stringify(reasons)); + }, + })), + ])), + m('tr', m('td', { + colspan: 9, + }, Button.component({ + className: 'Button Button--block', + onclick: () => { + const client = app.store.createRecord('oauth-clients'); + client.save({ + client_id: this.randomString(32), + client_secret: this.randomString(32), + }).then(console.log); + + // this.clients.push(Client.build({ + // + // })); + + // this.setting(settingName)(JSON.stringify(reasons)); + }, + }, app.translator.trans(this.translationPrefix + 'add_button')))), + ]), + ]), + ]) + }
); } + + randomString(len) { + len = len || 32; + let $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let maxPos = $chars.length; + let pwd = ''; + for (let i = 0; i < len; i++) { + //0~32的整数 + pwd += $chars.charAt(Math.floor(Math.random() * (maxPos + 1))); + } + return pwd; + } + + saveClientInfo(id, key, value) { + console.log(id, key, value); + } } diff --git a/less/admin.less b/less/admin.less index 9795d1f..29341b2 100644 --- a/less/admin.less +++ b/less/admin.less @@ -24,6 +24,35 @@ } } } + + .OAuthCenterPage-container { + max-width: 100% !important; + } + + .OAuthCenter-clientsPage { + table { + width: 100%; + + td, th { + padding: 3px 5px; + } + + th { + text-align: left; + } + } + + .FormControl { + background: @body-bg; + border-color: @control-bg; + + // We set the same as Flarum default, but with more specificity + &:focus, + &.focus { + border-color: @primary-color; + } + } + } } @media (min-width: 992px) { .OAuthCenter { diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index 7bcb0f0..8c7e4f2 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -15,10 +15,11 @@ foskym-oauth-center: redirect_uri: 回调地址(多地址请用空格分割) grant_types: 授权类型(可空) scope: 权限(可空) - name: 应用名称(可空) - description: 应用描述(可空) - icon: 应用图标地址(可空 可使用fontawesome图标) - home: 主页地址(可空) + client_name: 应用名称(可空) + client_desc: 应用描述(可空) + client_icon: 应用图标地址(可空 可使用fontawesome图标) + client_home: 主页地址(可空) + add_button: 添加应用 forum: page: From cf2abfccf76bb107e0c477c74c57510c4cea1392 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 16:55:27 +0800 Subject: [PATCH 02/35] feat(admin): clients controller --- extend.php | 6 ++- js/dist/admin.js | Bin 8327 -> 8366 bytes js/dist/admin.js.map | Bin 25169 -> 25319 bytes js/src/admin/pages/ClientsPage.js | 9 ++-- src/Api/Controller/CreateClientController.php | 39 ++++++++++++++++++ src/Api/Controller/DeleteClientController.php | 28 +++++++++++++ src/Api/Controller/ListClientController.php | 4 +- src/Api/Controller/UpdateClientController.php | 37 +++++++++++++++++ 8 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 src/Api/Controller/CreateClientController.php create mode 100644 src/Api/Controller/DeleteClientController.php create mode 100644 src/Api/Controller/UpdateClientController.php diff --git a/extend.php b/extend.php index bad30c4..926568e 100644 --- a/extend.php +++ b/extend.php @@ -27,8 +27,12 @@ return [ (new Extend\Routes('forum')) ->post('/oauth/authorize', 'oauth.authorize.post', Controllers\AuthorizeController::class), + (new Extend\Routes('api')) - ->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class), + ->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class) + ->post('/oauth-clients', 'oauth.clients.create', Api\Controller\CreateClientController::class) + ->patch('/oauth-clients/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) + ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), (new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class), ]; diff --git a/js/dist/admin.js b/js/dist/admin.js index 589a21ae64ba68aee1b50010ef57e7c5ecd50726..4459328aab2dfb48f4a64068cfc30fc22278765a 100644 GIT binary patch delta 231 zcmZp7T<5sKf=!^zwnQ&aBSq6XIX|zsL?M0h1vb&i3G70X^VtL$(>FJ=-Q{2`+Z@lo zft@jbvVgcXkn|CkGEdd4F3~GaEK7CH$xO{F@ytuh*T~b!*GbhYNi0fFEzv7W%qdOP ztgY451R|YW4W*J4C7rU#h7uZ+Pl=}ijWm?F$!J@aSfr2-wmLs2RWBz$U86)NRVPnV zrz9h@ST7lDc5!q`EZ8ay4UK%;>RQd{)L2`fU7DMvr2?23L1rpU?vXhUW!1>OhOjnw I$o*#o0H=ISF8}}l delta 188 zcmZ4I*zUN&f=wXZwnQ&aBSq6XIX|zsM4@c*1vb&i3G70X^VtL$%QiQ%-Q{3R-yF}s zft@jLvVgcXkn|CklFQeuF3~GaEK7CH$xO{F@ytuh*GSdNOwrKP$-*G?cYm_Bqfc{c`e50I@1QRR910 diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map index a4d7b3a43f1ae87d81a4beabb24a5a2d29bf9065..8aae698bc105e6162e9844f74cac1c3747a8952f 100644 GIT binary patch delta 843 zcma)4PiqrF6eqz-Kr9xULd~H|$U(`owoO9X6vQ{P`9Y_{BBRil1t;YQ<&2?!A4pnfX&bZ7tsZuks8xFW#GuSHv}{hTkBkF z_&jQ}kr!D}KnKywpDmHyF5h6vY59O@Pn?8m0Rv0EN|s^=@_VwF9-4~KRv!!Xku0d^ z50ou2WJfZ$z{Y`~OJN?H^k}l$AiXnTxnNOB`XO1B8)-j26-8TTIZakI^AV#El({Gi z$I%Q86`SoS2S{v0Qn*6}11qj}MdTKWu1=a$;9T`_d^GvG;KgTqTCxF$jK))xw-&)z z5sKG_V}_!wjF}^yiJo3PFlFq*W%+XP=0C77#fCJDt!gy$dnooa4dtkR0wU&9p6x6D z&C~ju=iwhbv#A$}CY1TsD$mI`sr5u&=y|s%KT{vC&-nd)Z!~#pzdnCXoupGwSJeTG zL+=R~LpM0`u5I4$8?**pKV0qvzSkdwI~usV9J)jA>eHxh7&`>oEk!7ZE}u=F*WX=| bId`0Vpa?Q21Q|_`3FUh?jQjg?X>aW}m6!3r delta 694 zcma)(!D7P@h#4-Cvz zrPhWzR%?lv`JTz&0)<$2z(w?`cKYJ3nulj|7uI7NJf!(N-4!Miu~9u1VC(0z>sF*c&6bxR z%2ef~Hyh27Bcz-`8cPktP!}$Vc3*K($)V(-Ick&rjGc47tN?hpBXOfPHbTcUxN(C* z8kh~yL5)XZ3gLb-bvevT?U{T{=!taw`pFzDMv{q~Yba2)8AMWzm+tqawk9s>&vQ5b zAuWug4|sA#xJL|y$dIMLKO I)Neb*U!@txvj6}9 diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index 594f0a1..ea80fe8 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -46,7 +46,7 @@ export default class ClientsPage extends Page { type: 'text', value: client[key]() || '', onchange: (event) => { - this.saveClientInfo(client.id(), key, event.target.value); + this.saveClientInfo(index, key, event.target.value); }, })) ), @@ -98,7 +98,10 @@ export default class ClientsPage extends Page { return pwd; } - saveClientInfo(id, key, value) { - console.log(id, key, value); + saveClientInfo(index, key, value) { + console.log(index, key, value); + this.clients[index].save({ + [key]: value, + }); } } diff --git a/src/Api/Controller/CreateClientController.php b/src/Api/Controller/CreateClientController.php new file mode 100644 index 0000000..5093c0c --- /dev/null +++ b/src/Api/Controller/CreateClientController.php @@ -0,0 +1,39 @@ +assertAdmin(); + + $data = Arr::get($request->getParsedBody(), 'data', []); + + $client = Client::build( + Arr::get($data, 'attributes.name'), + $actor->id, + Arr::get($data, 'attributes.icon'), + Arr::get($data, 'attributes.description'), + Arr::get($data, 'attributes.actions'), + Arr::get($data, 'attributes.metrics'), + Arr::get($data, 'attributes.requirements'), + + ); + + + $client->save(); + + return $client; + } +} diff --git a/src/Api/Controller/DeleteClientController.php b/src/Api/Controller/DeleteClientController.php new file mode 100644 index 0000000..17907d0 --- /dev/null +++ b/src/Api/Controller/DeleteClientController.php @@ -0,0 +1,28 @@ +getQueryParams(), 'id'); + RequestUtil::getActor($request) + ->assertAdmin(); + + $client = Client::find($id); + + $client->delete(); + + return $client; + } +} diff --git a/src/Api/Controller/ListClientController.php b/src/Api/Controller/ListClientController.php index caa3307..b0e10bf 100644 --- a/src/Api/Controller/ListClientController.php +++ b/src/Api/Controller/ListClientController.php @@ -16,9 +16,7 @@ class ListClientController extends AbstractListController protected function data(ServerRequestInterface $request, Document $document) { $actor = RequestUtil::getActor($request); - if (!$actor->isAdmin()) { - return []; - } + $actor->assertAdmin(); return Client::get(); } diff --git a/src/Api/Controller/UpdateClientController.php b/src/Api/Controller/UpdateClientController.php new file mode 100644 index 0000000..1bc2478 --- /dev/null +++ b/src/Api/Controller/UpdateClientController.php @@ -0,0 +1,37 @@ +assertAdmin(); + + $id = Arr::get($request->getQueryParams(), 'id'); + $client = Client::find($id); + + $data = Arr::get($request->getParsedBody(), 'data', []); + + collect(['client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'client_name', 'client_desc', 'client_icon', 'client_home']) + ->each(function (string $attribute) use ($client, $data) { + if (($val = Arr::get($data, "attributes.$attribute")) !== null) { + $client->$attribute = $val; + } + }); + + $client->save(); + + return $client; + } +} From 1985bd68ca12c0cf925459148a0221098430ebba Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:00:51 +0800 Subject: [PATCH 03/35] feat(admin): clients controller --- src/Api/Controller/CreateClientController.php | 22 +++++-------------- src/Api/Controller/ListClientController.php | 2 +- src/Api/Controller/UpdateClientController.php | 6 ++--- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Api/Controller/CreateClientController.php b/src/Api/Controller/CreateClientController.php index 5093c0c..f1b7b2c 100644 --- a/src/Api/Controller/CreateClientController.php +++ b/src/Api/Controller/CreateClientController.php @@ -18,22 +18,12 @@ class CreateClientController extends AbstractListController $actor = RequestUtil::getActor($request); $actor->assertAdmin(); - $data = Arr::get($request->getParsedBody(), 'data', []); + $attributes = Arr::get($request->getParsedBody(), 'data.attributes'); - $client = Client::build( - Arr::get($data, 'attributes.name'), - $actor->id, - Arr::get($data, 'attributes.icon'), - Arr::get($data, 'attributes.description'), - Arr::get($data, 'attributes.actions'), - Arr::get($data, 'attributes.metrics'), - Arr::get($data, 'attributes.requirements'), - - ); - - - $client->save(); - - return $client; + return Client::create([ + 'client_id' => Arr::get($attributes, 'client_id'), + 'client_secret' => Arr::get($attributes, 'client_secret'), + 'user_id' => $actor->id, + ]); } } diff --git a/src/Api/Controller/ListClientController.php b/src/Api/Controller/ListClientController.php index b0e10bf..566fba0 100644 --- a/src/Api/Controller/ListClientController.php +++ b/src/Api/Controller/ListClientController.php @@ -18,6 +18,6 @@ class ListClientController extends AbstractListController $actor = RequestUtil::getActor($request); $actor->assertAdmin(); - return Client::get(); + return Client::all(); } } diff --git a/src/Api/Controller/UpdateClientController.php b/src/Api/Controller/UpdateClientController.php index 1bc2478..e2cfee1 100644 --- a/src/Api/Controller/UpdateClientController.php +++ b/src/Api/Controller/UpdateClientController.php @@ -21,11 +21,11 @@ class UpdateClientController extends AbstractListController $id = Arr::get($request->getQueryParams(), 'id'); $client = Client::find($id); - $data = Arr::get($request->getParsedBody(), 'data', []); + $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); collect(['client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'client_name', 'client_desc', 'client_icon', 'client_home']) - ->each(function (string $attribute) use ($client, $data) { - if (($val = Arr::get($data, "attributes.$attribute")) !== null) { + ->each(function (string $attribute) use ($client, $attributes) { + if (($val = Arr::get($attributes, $attribute)) !== null) { $client->$attribute = $val; } }); From 6c537e4b80d00fadc11b10d3d05c9278f97203ee Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:11:29 +0800 Subject: [PATCH 04/35] fix(admin): create client --- js/dist/admin.js | Bin 8366 -> 8388 bytes js/dist/admin.js.map | Bin 25319 -> 25503 bytes js/src/admin/pages/ClientsPage.js | 8 +++++--- src/Models/Client.php | 13 +++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index 4459328aab2dfb48f4a64068cfc30fc22278765a..9a933c92605ee1b910c40095a3f6b266db667421 100644 GIT binary patch delta 133 zcmZ4Ic*Jo-o&;N2Vv$0s?c_WO^-P^S+Y-H^#JrUJ+~AU;%)E3BV5C4jq2o_%+$P+_{MY4+#Bz$sD`zv$X9An1apkgU z>_6WgTa@AXGRa{QVZau{oRk2{fOfXTNi_mc17u~ZA*P}-il9ac0EG>zO!r9|@^OkM zV@dI>KXEanY6DWl0@LD4e`s{ika?y&(h?lZ9c9V24MgW{x+}(gRCC0Z??#s`Nw6tb zy!6G^ODG1I1(~EOY0_i{xxlJOQx1dE!0S|gSdwBF7{5-EF=^uj@hOFYZOyh)L5sIyhzs2X5mVrGACupf|*030(AeSNu{z$ zb}8^B*_-i1ycsl89_aRI(D+$FwMnt82XRf>dR9w_w|d{zGnRvyJpq|H9+=V^q7oRH z^VDLvC)h$6wPabj{P)(>B;eSM<3@K0-TdK{dNXg?il{1UdV3cW9|D6o_-}!fmN*;< zevI^NIxTm&y56Wc?n+~I__i3beBvPI@2{Trv})C6&Hd*UKj$J{f3w84`^k>s}!^8F8>SV`Le delta 1094 zcma)5&rcIU6wYc4@gN3){uU9Vf}PNoF3_r%H?w2AZI)U}1riSwsBNKaNn1ckjPc;z zWG>!}C*r}xq$mFX^=Q26)x?W;<4NC}1%n3@_OO|GzrOFi_sz?X#`pKe+nWP@jm#1& zz(x-SzMXzjbS-8Be#`+VcPv%`sIUeH5#xg80rE_MxR;i!46v9IOrohFyf7QYET5HZ z4WMfN>vBNUMVjjhHO`6vMS(ztCTAHCB1sqg)YswIxtgSMz)A=$l;0N}+qDSCre6m1 z5t$Kkm)Oc(zN6NC+-Rx;-;J};47w1lt-kooW(j)(yGYT1v7*hVvj_=JMHj%}49GgC ziN4aIEvJ*V5 zMuHbpGoCGnsdkf6B}@~pfT;H9Nni@@ah_CDz*a=IZmE&b$Zb@~f~kSFIID4hO-@@# zSQ}adCANt+XI3*pDwOXKN#XK+6$|?Z<9gaQ+v6aY2-SM1eg6P`Ts;p( zP#5W>T zrf~a<*rdqO`#HDUveG-csaK zTpc*E;cmUrnQT|w_10FY+itkE@#NHm`kWtDE6y49%jy4rL~wNU@x)}eUUkRUT5hM+ jtWGvtwTWBzUG-`%*lWzihXy;9-Rc+{I}V_Ft3Un#5*Rb3 diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index ea80fe8..90f993b 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -66,10 +66,12 @@ export default class ClientsPage extends Page { className: 'Button Button--block', onclick: () => { const client = app.store.createRecord('oauth-clients'); + const client_id = this.randomString(32); + const client_secret = this.randomString(32); client.save({ - client_id: this.randomString(32), - client_secret: this.randomString(32), - }).then(console.log); + client_id: client_id, + client_secret: client_secret, + }).then(this.clients.push(client)); // this.clients.push(Client.build({ // diff --git a/src/Models/Client.php b/src/Models/Client.php index 840b713..c9e2c98 100644 --- a/src/Models/Client.php +++ b/src/Models/Client.php @@ -15,4 +15,17 @@ use Flarum\Database\AbstractModel; class Client extends AbstractModel { protected $table = 'oauth_clients'; + + protected $guarded = []; + + public static function build(string $client_id, string $client_secret, int $user_id) + { + $client = new static(); + + $client->client_id = $client_id; + $client->client_secret = $client_secret; + $client->user_id = $user_id; + + return $client; + } } From 8e8f49ae876dde9bd6e43cdd6c1bd0ef895024b5 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:13:49 +0800 Subject: [PATCH 05/35] feat(admin): delete client --- js/dist/admin.js | Bin 8388 -> 8410 bytes js/dist/admin.js.map | Bin 25503 -> 25314 bytes js/src/admin/pages/ClientsPage.js | 8 +------- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index 9a933c92605ee1b910c40095a3f6b266db667421..8a2bc57fc0ea55e7c83bcba7e4348f148cdd8d7b 100644 GIT binary patch delta 26 icmX@&c*}9aZ*kt}yjZ=I)ST3kR1Hm?&7Z_CaR30C1`5gm delta 12 TcmccRc*JqTZ}H875+^wTDU1b> diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map index 7eef73c14d305bcda330b20bcdc698d8767f8d76..89380b76ce38586b0ebb753647f9d6ea35558b27 100644 GIT binary patch delta 102 zcmV-s0Ga=v#{uHS0kAp|2sTDoEKflO)OJELvBKLld2RO0Y$UM z6a@hRL$k~kcmV-uvqcvaG!a{AZe(S6T`pv0Y-Mz1C@DLW@mLs>O-nYj&`W>w{Et0#(;)YFfwSfp{h`y(GFo4Cn%p$)}?vHuw7livR$hl3AYs diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index 90f993b..5bf8831 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -54,9 +54,9 @@ export default class ClientsPage extends Page { className: 'Button Button--icon', icon: 'fas fa-times', onclick: () => { + this.clients[index].delete(); this.clients.splice(index, 1); - // this.setting(settingName)(JSON.stringify(reasons)); }, })), ])), @@ -72,12 +72,6 @@ export default class ClientsPage extends Page { client_id: client_id, client_secret: client_secret, }).then(this.clients.push(client)); - - // this.clients.push(Client.build({ - // - // })); - - // this.setting(settingName)(JSON.stringify(reasons)); }, }, app.translator.trans(this.translationPrefix + 'add_button')))), ]), From 8ad3fd087fc5d656a953ace8f3342a4bd4600f93 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:16:45 +0800 Subject: [PATCH 06/35] fix(model): add guarded --- src/Models/AccessToken.php | 1 + src/Models/AuthorizationCode.php | 1 + src/Models/Client.php | 1 - src/Models/Jwt.php | 1 + src/Models/RefreshToken.php | 1 + src/Models/Scope.php | 2 +- 6 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Models/AccessToken.php b/src/Models/AccessToken.php index 502d559..4204e88 100644 --- a/src/Models/AccessToken.php +++ b/src/Models/AccessToken.php @@ -15,4 +15,5 @@ use Flarum\Database\AbstractModel; class AccessToken extends AbstractModel { protected $table = 'oauth_access_tokens'; + protected $guarded = []; } diff --git a/src/Models/AuthorizationCode.php b/src/Models/AuthorizationCode.php index 8b34f73..f144175 100644 --- a/src/Models/AuthorizationCode.php +++ b/src/Models/AuthorizationCode.php @@ -15,4 +15,5 @@ use Flarum\Database\AbstractModel; class AuthorizationCode extends AbstractModel { protected $table = 'oauth_authorization_codes'; + protected $guarded = []; } diff --git a/src/Models/Client.php b/src/Models/Client.php index c9e2c98..d6dc3d2 100644 --- a/src/Models/Client.php +++ b/src/Models/Client.php @@ -15,7 +15,6 @@ use Flarum\Database\AbstractModel; class Client extends AbstractModel { protected $table = 'oauth_clients'; - protected $guarded = []; public static function build(string $client_id, string $client_secret, int $user_id) diff --git a/src/Models/Jwt.php b/src/Models/Jwt.php index d9ee703..652a3c4 100644 --- a/src/Models/Jwt.php +++ b/src/Models/Jwt.php @@ -15,4 +15,5 @@ use Flarum\Database\AbstractModel; class Jwt extends AbstractModel { protected $table = 'oauth_jwt'; + protected $guarded = []; } diff --git a/src/Models/RefreshToken.php b/src/Models/RefreshToken.php index 7f6bea0..92919f4 100644 --- a/src/Models/RefreshToken.php +++ b/src/Models/RefreshToken.php @@ -15,4 +15,5 @@ use Flarum\Database\AbstractModel; class RefreshToken extends AbstractModel { protected $table = 'oauth_refresh_tokens'; + protected $guarded = []; } diff --git a/src/Models/Scope.php b/src/Models/Scope.php index 125bf94..b191afc 100644 --- a/src/Models/Scope.php +++ b/src/Models/Scope.php @@ -15,7 +15,7 @@ use Flarum\Database\AbstractModel; class Scope extends AbstractModel { protected $table = 'oauth_scopes'; - + protected $guarded = []; static public function get_path_scope($path = '') { return self::where('resource_path', 'like', $path . '%')->first(); From 7067581f4407f9b5d78ce6d5c19ad94a0d42febf Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:30:18 +0800 Subject: [PATCH 07/35] feat: get client info --- js/dist/forum.js | Bin 3225 -> 3312 bytes js/dist/forum.js.map | Bin 11465 -> 11744 bytes .../forum/components/oauth/AuthorizePage.js | 8 ++++++ src/Api/Controller/ShowClientController.php | 27 ++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 src/Api/Controller/ShowClientController.php diff --git a/js/dist/forum.js b/js/dist/forum.js index 3003770dcb5e07faa49bcbfd297579fbb652810d..83ca55c8a94579841b3ea060fc329507292cae13 100644 GIT binary patch delta 255 zcmbO!`9X36BQsa2ZHZou2`HZELS2Jq?$!pBIK$3+;8%P?kr~t`O76l+# z#-au!=dys*oB)%b!K56kK2XGu)rc{9awDt7kv-Cr8mXUoSZ)Gc~UyJ~Ks44JK5ST3nEySDYGO zQdy9SES!>Al$u-;Us{w|Qv)-vIJHDWNnc5`RwrK%$PURY$w{?ME6qzT$;{8w(5&8^ P&9RAzF=ewHcQqpb{11x^`HabvS2Jq?$!pBIK$3+;8%P?kr~t`O76l+# z#-au!=dys*oB)%b!K56kK2XGu)rhflawDt7DO?3p=p&dlU<`}>oR?V0RdUg2y57F96w_P8RL z3*ZUn0QmZK1oJe~027Y+8f7;QINJhP(&?8xRrj+uS|MlkQ!)-D zoK4aP4599`CP0&g97Ol=KX4D+*w{d`f;a*ec}d6qzWR_YXA<=_d%ZBQHCM1zDk6V| z2O~{~XO6m-yPX@DugFnuZq~yb`l<_>#P3ssKRcz(vNn!j)LWPo_6yD$)Si~0=h!`C zSbfSB(ag8p@!a@=I1JN#g(1mB~m}KWHgafXDW|Q-ranVKW9YM Tm(rCBe+d^@0XwK4rJuh6TO{i~ delta 521 zcmZWmO-lk%6vdU!2(Bz#6oS+ux?~0sE+p=|Zz_|~avG$VP(x2g2H+tg1V~OD%6dfxnjY`r-Y*g$9{WZB`Vy%~4fT|m4cbr{b6MA^vM%Zs zD>d*Dedr0K*3Lh;jpbov;#2@Jhj1ts&F-D4l(iJQR3&RB*O7)xu*n~>y>r9EUi2tR zb!*LAo#>R8>e?f^oaAiA9^AUP1Q%ktcT$#G-gD|W5E?759At{%O*v2bFhhFqkAG+Ep=p>xnSG?7pz zjw<*0YSM$4;TF_UGLv2roWS3okXlxc$xLc>Of&ywG)k7HNB22tt9MANZ}|KHV9bvp diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index e853bd6..30fd7a4 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -6,6 +6,7 @@ import LogInModal from 'flarum/forum/components/LogInModal'; import extractText from 'flarum/common/utils/extractText'; export default class AuthorizePage extends IndexPage { + params = []; oninit(vnode) { super.oninit(vnode); if (!app.session.user) { @@ -13,6 +14,13 @@ export default class AuthorizePage extends IndexPage { } const params = m.route.param(); + + if (params.client_id == null || params.response_type == null || params.redirect_uri == null) { + m.route.set('/'); + } else { + this.params = params; + + } } setTitle() { diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php new file mode 100644 index 0000000..39adda5 --- /dev/null +++ b/src/Api/Controller/ShowClientController.php @@ -0,0 +1,27 @@ +getQueryParams(), 'id'); + RequestUtil::getActor($request)->assertUser(); + + $client = Client::findOrFail($id); + $client->client_secret = ''; + + return $client; + + } +} From 44584fb882570135ff1402264dec07ca6ab89e24 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:34:20 +0800 Subject: [PATCH 08/35] feat: get client info --- js/dist/forum.js | Bin 3312 -> 3508 bytes js/dist/forum.js.map | Bin 11744 -> 12157 bytes .../forum/components/oauth/AuthorizePage.js | 5 ++++- src/Api/Controller/ShowClientController.php | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 83ca55c8a94579841b3ea060fc329507292cae13..d05dddc97aa353659689b2ccdfe406a5d0688eae 100644 GIT binary patch delta 299 zcmew$xkY*dBQsaBZHZo11x^`HabvS2Jq?$!pBIK$3+;8%P?kr~t`O76l+# z#-au!=dys*oB)%b!K56kK2XGu)rhflb0h0N#>uM8)sh8?MTxn^w$ZUVsd~vdnW=dt zwt1yFIXbD6Z*qoB{>h$NZ)=+mm5I+xsi^_Uf`p1viwpAeic{lDDhpDPg;O$%Qj<&K zON%n?bM=byOG{Gqic?E8l=PJ}tu#t9GK=+~cINAVc~DymG&J>!OY)0S_0m&IoGLYx i@)Ju-GIWy_z>X?b(oupa1Uf=V2gya6n^$tUvj6~&RAwar delta 192 zcmdlY{XudABQsa2ZHZopCSrmX|8H*Z_oXY}Ia{^3$29t8E`alssRwKsb&5f-87$;Y9RZY(1NcC2<&DTrL z$xO{FiO) diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index 28515cdbed928f8985ea5157785db9997ba36935..1b1cfe442bb0da51f83b9d63afbbe935f2b696e9 100644 GIT binary patch delta 1134 zcmZuwOKuZE5LJYP^Fc&Hir4@eETkm3V-kggSWy<$J%gD{91|SJvCSuAdty5{wy`H) z33b{^|$HR^&J2RrT%)& zA2@9(vheg+ZVLyaCz3x)N_co$lp=$lx(Q+(z#*@joW`VTs16Z8PNV^xbE;JP7f}c~ z+)F7G;&8zx&zXJI@F|3pslSW)G-oz>T~;Cwk7WsYS7b4vh_j-&vB&{r38=QVxORnV zAyc<0ok_87BR-+O#I|C)RF%u?U$NVR6792xq5!a}=w|0K;E*o@yroT{Q(56qN%)|8 zPM@VZT%AdiQWvY761VW!j2s|9)dI4_tFad@UkQjWU!XN3>Jp03l%fdWH<*-#IHwM^ zQ-mvpg`r6A`T4rKJAN@D1!2Xs$uQepi-))Kabzte=E&U2#hL}vq#K8g1iEm zlow5jM($q;SHbPEBy~C(R!Sy#pF7hxCz4~AdSl|wpl>sl{6}IMTgW(gXFgpA`{Wxm zs=c~0gF8}JCWkMEl=Z0k|D)pxR|;%to;=ANB4h)iL6~u%mnvm+(^ZvyCI!80wvQb! zMn@LtnaTLPD?H_`D3nd=0f&r3c|iwPtVw`1N$4YcM;}Zk#ve(%X}XfdgLP{W&D-YJ zR@g>>gW>O!<+&ra-P>iY{D)CXHv5!mDXdeQ^pc>XpG`d(??%P?!&G9dIvh@Ynz`5Y zd;W3X+OW#6)?cZv- zZtpMf?!lyY<1g?x_&o|2`uS~_PL2YMEa)j6d>W3SYMIxhdd5(RoXFq z5hczDv2WK(^|4^55)HDd7}YxD=}-$ua-!8H>5}$a{aW-Tq3Qzc1pMSguQFLO)T#qG zGKVs823O-1LJA>mO;gyWXo3z)1vTCTG)>u3#AhweTU%!pqU~m)N*x4%kLWQU1c(Rr z7!HY(L0KpUeJz`jS~PSIG#lImK24PJAsVW$NkM*SF5jKjI}na?C_+SjgmPcb(?eTy zy!x>m;6JVn0--wRS`G&Xf(pBa_!~X;;n@!Q_JecXALOllZvE>~Zjo5oCJ3@ELOxmg z(*AI6+-l0cZ!~#DQvdGz>fFBein~yV?0t7`?g?KlR8 { + this.client = client; + }); } } diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 39adda5..3b88c8d 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -15,10 +15,10 @@ class ShowClientController extends AbstractListController public $serializer = ClientSerializer::class; protected function data(ServerRequestInterface $request, Document $document) { - $id = Arr::get($request->getQueryParams(), 'id'); + $client_id = Arr::get($request->getQueryParams(), 'client_id'); RequestUtil::getActor($request)->assertUser(); - $client = Client::findOrFail($id); + $client = Client::whereOrFail('client_id', $client_id); $client->client_secret = ''; return $client; From 35d9f280fb29bc7ccc9a6e7c5ec85a7d4b7b7e05 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 17:41:52 +0800 Subject: [PATCH 09/35] fix: get client info --- extend.php | 1 + js/dist/forum.js | Bin 3508 -> 3541 bytes js/dist/forum.js.map | Bin 12157 -> 12321 bytes .../forum/components/oauth/AuthorizePage.js | 3 ++- src/Api/Controller/ShowClientController.php | 7 +++++-- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/extend.php b/extend.php index 926568e..cebf87a 100644 --- a/extend.php +++ b/extend.php @@ -31,6 +31,7 @@ return [ (new Extend\Routes('api')) ->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class) ->post('/oauth-clients', 'oauth.clients.create', Api\Controller\CreateClientController::class) + ->get('/oauth-clients/{client_id}', 'oauth.clients.show', Api\Controller\ShowClientController::class) ->patch('/oauth-clients/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), diff --git a/js/dist/forum.js b/js/dist/forum.js index d05dddc97aa353659689b2ccdfe406a5d0688eae..7564cab6f04bfac660dbd72f6ada1a5e1cd14261 100644 GIT binary patch delta 248 zcmdlYeN}qHPS(lyS;Z!wXBA*fnf!p&8c52p)iRa=*=myyunDjy*_P<#X_Rfg&Q`?8 zU6xp+kZ)U(ky&g#*^?vRxyUwGuPDE?Bvr2aRWWok7i=WxDdOxhg9 Ob&ruTZL=j$H6sAalUdXN delta 201 zcmcaAy+wM%PS(lyS;Z!wXBA*foBV*)8c52p)iNdl*=myyunDl2*_P<#X(VmF&Q`=Y z`3slAt38aXMVo<=9~HR;pXGd@znByK2*D~s4EMoT)-;Q z3qTbCc2RB7sq*w@A6W~4hdU;lni+9TIpyxZWplC2r;Ex1@KEjDU%R@>_T6Ju23QmC zr4GbYQvpE3;e>Nt7t^8g0ekM5xl292ZfYh`1oB|r69T}&r7|&qf@)}hP@m|3_~lRv z6qq-VV+$~H^6W2c4`H2Zq6d4(kok!7k!t0^-R4l_E?uX6tp$d7qkDW`opAjIheAa% zSPkkc2(`4WIu77Vq{^%os2Tv(BKWS5M8-#_ubDq5qD!pMt#Vmlf`ytYQG+VffJ;@; zVOO8)jExB zU32#*PSJeLJe|ynAf9Sd*E`4xlq06NRo!F%NY;GMydKG!yUg_BTCx-*DDS|5oMiJz zFGrg5VxB8WO`8N42F4~zO_?+?P&;XPb#C^ z8lWTtzx^@xWa8TIcI|%L=>_(27}e)yJN{YRd{JwKK@|6AmDTloe!FichNG}PZ^z9b znoHi+#-{c8ePlg+aWfpmS{qgp^lCVu)`|L^R$#X}4Z(OE#q$pVUv5XISJID;7-iYy X?CKrX$J#^I8x9;42J5wpF4LY zCeFC%I-$r%)V1s~5-iGI4b=d2_qdG?w`?bfYi)^WDgX*efd7_M(^^?zkh>#U3+=HF7bD zuBY!Tb5rYlAa2*?Qid(IeoG1Mz|r5*SFg>CBOV;_*xMu)G}jd?FLrABd-_UZrhleO zi4A=}vr@XJ%tj9krLt=jGv*;}IA&(=khl#!m;VCC5{pJ(G!h>q4DYehA2Ul&SOw4O z^Lpf8vBfr(Fi#x&5M~P9x?!>;Tgxo`>{sUUQZ*iqrupvSD0~xVpJsz7%1`6*B+L)O vSRLQaje}V{yleB*9AtAg+#mJ$5(Sgs=pUP*vkxl|Qu=Ft|AJv_wf^HTQvvhu diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index ee48f3c..467eeb8 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -20,8 +20,9 @@ export default class AuthorizePage extends IndexPage { m.route.set('/'); } else { this.params = params; - app.store.find('oauth-clients', {'client_id': params.client_id}).then(client => { + app.store.find('oauth-clients', params.client_id).then(client => { this.client = client; + console.log(client); }); } } diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 3b88c8d..2b662d7 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -16,10 +16,13 @@ class ShowClientController extends AbstractListController protected function data(ServerRequestInterface $request, Document $document) { $client_id = Arr::get($request->getQueryParams(), 'client_id'); - RequestUtil::getActor($request)->assertUser(); + RequestUtil::getActor($request)->assertRegistered(); $client = Client::whereOrFail('client_id', $client_id); - $client->client_secret = ''; + + if (isset($client->client_secret)) { + $client->client_secret = ''; + } return $client; From 7a82b15c49c0c25bbff475d70bb8062594d4980c Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 18:18:43 +0800 Subject: [PATCH 10/35] 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+@kuVb^V=l;HHn|**D5I&qR}=wv0f5x za-!$PMfoMxc8B?=tT|Owbax9kN`r}rrf9eq`3mVQy2HW(Ytfw*_iN!=u|LVT+(}`B zZJbqpSzIVTm}EAD-2XrFnQ^a+YcytWwvr9IT*+sKq5FC^rP*}@G^vH47h%-pqM_3` z4nuQ3se^;*k$W{eM_`4L92?o=B1o)32s%n{aoP298Ky%(nb=xYV zxfMgz;k7U%d2cNgr%fbaxxeO%2E+*raoR*^H*4QEvZjGb5Vpn&p>3NfsvzmbifTNn z$qX?u1hLuXASNBscBb7RvKCc~L~_4llHEafb=obh0w4iCP6@CH`w@W>{297Wd%Su( z3?U$mu)opaCZkv5Q+mo@ZvFjvqc}EuP1Pj@ZDlhq- zgFMhQg*G%38(GL$P91(Hahbvwqmd9|BrzaU9x59{c;=w{v2>L^aL-Du&oJmK*gH>& zA%aa&d)a%N`geyo~s^nSq!ll!N(@_`Po6q@1l%T#cj?7blj5=ru+1`WGdqhC*fjMM z*v#33@#snW0rcq2lX}%JpeEjoQ3pz@XD`3Z%=>Si=l!w%zVzfeg0o_M2k69WKtd=a zwA;Xp0&#aIJrH>030v3!w}D6pFi=4%m5tevQE_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x3vc{-(If*c@By L-Awn&TzT;~0f+|E delta 595 zcmZWmO-lk%6vb#^LLH)R!qqBChVcGnfvOh=~|3(#ia28YBBI=ttaTtNI0j z+g3%tqD8BIMVsDxW(3V*=DsuMynD{Q@12LeC*ALl@LiUNb>5%$=X`gbk!2=;l@k~g zLDaZ^$XNlPfGi7;^|-`ZTpY}tq#}y9X&iA@1OQeBG!GnAB@-%2F!&FRHfJ_~ z&AJ9)3OkA+=nen{$0sU1&aB~8!Umdk*$1Q}%V8ye5^Hn7`u;!If$WL&2e`o*N)18> zBdRVYIDL(;jU=lwtc+t^sqb1_&2wC8AkL3`s;q6Q#m#QC^>&YNPa7I{$lDlWz4{ z-5u)6AePa8)T=X8Seaf*SG~pG$LV^#uG@&Z-R7#}wj17QC{6v|G3|#D LWI@59+r-B=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 + ]; + } +} From c29b8f7fff9e6b4eb7bb02da3284b015493b2a3a Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:14:59 +0800 Subject: [PATCH 11/35] feat: authorize page --- js/dist/forum.js | Bin 4090 -> 6146 bytes js/dist/forum.js.map | Bin 13659 -> 20023 bytes .../forum/components/oauth/AuthorizePage.js | 167 ++++++++++---- less/forum.less | 1 + less/forum/oauth.less | 218 ++++++++++++++++++ 5 files changed, 338 insertions(+), 48 deletions(-) create mode 100644 less/forum/oauth.less diff --git a/js/dist/forum.js b/js/dist/forum.js index 2422d75c017c9af68f12a51062aefe48d9701d4a..1ab32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|d4Q$?OLxshs@{y$WJRA!y3rc6$6bNPX+=U$mL zkq6wnmVb%?zkbO`NeZ9$ju-Y`}^STkH+Tgl-34Zwx{R|1b@k5-@(iqa zT2y%cWt5Az*+RwT@q|xnPpO@-ru^j&j8H%TKnyjk4EWQe`%k^R25po~Gqp$M$@-y@u;vrC;$9 z-HK`SQEcX!{T*+|qwium{ShmYtq=9=YqndrwRhS5ss0juqc2gfc$t2h8m9O4Q}mv= z(3`J%bzf`L9Em~q;sf+X{P|PTTXpS8x4JtnV-t)`kK^}fPMoF1sb2aa9;fdo=by4a znKIh;alu?P_1l-F@}@kBqNdetf6eh-dwfE1TS>U|ZQ=z`DNV<|6ZmD7Q`E-K`z5D7 z84RupWI)quw%@3E+Su4X0JM_Gk7~L$#(!OVqO4tg%ga{m2{p`7;v8ko7?q~`=!5Ao zdN_B2?wirW53$g#*Y{k app.modal.show(LogInModal), 500); - } + params = []; + client = null; - const params = m.route.param(); - - if (params.client_id == null || params.response_type == null || params.redirect_uri == null) { - m.route.set('/'); - } else { - this.params = params; - app.store.find('oauth-clients', params.client_id).then(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('/'); - } + oninit(vnode) { + super.oninit(vnode); + if (!app.session.user) { + setTimeout(() => app.modal.show(LogInModal), 500); } - }); - } - } - setTitle() { - app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize'))); - app.setTitleCount(0); - } - view() { - if (!this.client) { - return ''; + const params = m.route.param(); + + if (params.client_id == null || params.response_type == null || params.redirect_uri == null) { + m.route.set('/'); + } else { + this.params = params; + app.store.find('oauth-clients', params.client_id).then(client => { + if (client.length === 0) { + m.route.set('/'); + } else { + this.client = client[0]; + let uris = null; + if (this.client.redirect_uri().indexOf(' ') > -1) { + uris = this.client.redirect_uri().split(' '); + } else { + uris = [this.client.redirect_uri()]; + } + + 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('/'); + } + } + }); + } + } + + setTitle() { + app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize'))); + app.setTitleCount(0); + } + + view() { + if (!this.client) { + return ''; + } + return ( +
+
+
+
+
+

{app.forum.attribute('title')}

+

+ {app.translator.trans('foskym-oauth-center.forum.authorize.access')} {this.client.client_name()} +

+ +
+
+ +
+ + + + + +
+
+
+
+ +
+
+
+ 保持对已向 计量便民平台 授予访问权限的数据的访问权限
+ + 即使当前没有使用该应用,也允许 计量便民平台 查看和更新你授予其访问权限的数据。这不会向 + 计量便民平台 授予任何其他权限。 +
+
+
+
+ +
+
+
+ 读取用户个人资料
+ + 访问该用户(mouse123)的个人信息、最新动态等 +
+
+
+
+ + + + + +
+ + +
+
+ + +
+
+
+
+
+ ); } - app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize') + ' ' + this.client.client_name)); - app.setTitleCount(0); - return ( -
-
-
-
- ); - } } diff --git a/less/forum.less b/less/forum.less index e69de29..8a23319 100644 --- a/less/forum.less +++ b/less/forum.less @@ -0,0 +1 @@ +@import url('./forum/oauth'); diff --git a/less/forum/oauth.less b/less/forum/oauth.less new file mode 100644 index 0000000..b76de17 --- /dev/null +++ b/less/forum/oauth.less @@ -0,0 +1,218 @@ +.oauth-area { + display: block !important; + position: relative; + left: 0; + top: 0; + padding: 110px 0; + min-height: 100%; + box-sizing: border-box; +} + +.oauth-main { + position: relative; + width: 376px; + margin: 0 auto; + box-sizing: border-box; +} + +.oauth-main::before { + backdrop-filter: blur(20px); + content: ''; + position: absolute; + width: 100%; + height: 100%; + left: 0; + top: 0; + box-shadow: 0 25px 50px #00000030; + background: hsla(0, 0%, 100%, .3); +} + +.oauth-box { + padding: 20px; + background-color: #f3f3f3; +} + +.oauth-header { + backdrop-filter: blur(0); + text-align: center; + box-shadow: 0 5px 10px -5px #d2d2d2; +} + +.oauth-header h2 { + margin-bottom: 8px; + font-weight: 600; + font-size: 40px; + color: #000; +} + +.oauth-header p { + font-weight: 400; + font-size: 20px; + color: #333; +} + +.oauth-body .oauth-form-item { + position: relative; + margin-bottom: 15px; + clear: both; + *zoom: 1; +} + +.oauth-body .oauth-form-item:after { + content: '\20'; + clear: both; + *zoom: 1; + display: block; + height: 0; +} + +.oauth-icon { + position: absolute; + left: 4px; + top: 1px; + width: auto; + line-height: 35px; + text-align: center; + color: #999; + padding: 0 8px; + font-size: 14px; +} + +label:before { + color: #999; +} + +@media screen and (max-width: 768px) { + .oauth-area { + padding-top: 60px + } + + .oauth-main { + width: 300px + } + + .oauth-box { + padding: 10px + } + + .oauth-main::before { + backdrop-filter: none; + } + + .oauth-header { + background-color: #fff; + } + + body { + margin: 0 + } +} + +@media screen and (max-width: 600px) { + .oauth-area { + padding-top: 0 + } + + body { + background: #f3f3f3 !important; + } + + .oauth-main { + width: 100%; + } + + .oauth-main::before { + box-shadow: none !important; + } + + .oauth-header { + box-shadow: none; + } + + .oauth-box:last-child { + box-shadow: 0 5px 10px -5px #d2d2d2; + } +} + +.oauth-top { + text-align: center; + padding-bottom: 20px; + position: relative; +} + +.oauth-top img { + width: 64px; + border-radius: 50%; + border: #4950578c solid 1px; + box-shadow: 1px 0 0 0 #e8e8e8, 0 1px 0 0 #e8e8e8, 1px 1px 0 0 #e8e8e8, inset 1px 0 0 0 #e8e8e8, inset 0 1px 0 0 #e8e8e8; + transition: all .3s; +} + +.oauth-top img:hover { + box-shadow: 0 2px 8px rgba(0, 0, 0, .3); +} + +.oauth-top i { + top: -24px; + position: relative; + padding-left: 10px; + padding-right: 10px; + color: #111; +} + +.oauth-scope-area { + padding-top: 10px; + padding-bottom: 10px; + overflow: auto; + max-height: 350px; + position: relative; +} + +.oauth-scope { + margin-top: 15px; +} + +.oauth-scope:first-child { + margin-top: 0; +} + +.oauth-scope, .oauth-scope-body { + overflow: hidden; + zoom: 1; +} + +.oauth-scope-body, .oauth-scope-left, .oauth-scope-right { + display: table-cell; + vertical-align: top; +} + +.oauth-scope-left, .oauth-scope > .pull-left { + padding-right: 10px; + min-width: 42px; + text-align: center; +} + +img.oauth-scope-object { + display: block; + vertical-align: middle; + border: 0; + width: 32px; + height: 32px; +} + +.oauth-scope-body { + width: 10000px; + padding-left: 8px; +} + +.oauth-scope-heading { + margin-top: 0; + font-weight: 800; + color: #382e2e; +} + +.oauth-scope-body small { + font-weight: 500; + font-size: 12px; + color: #aaa; +} From 465a005d05aafaf6ebd05b354978222437efdf6d Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:17:03 +0800 Subject: [PATCH 12/35] chore: simplify locale(cn) --- locale/zh-Hans.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index 8c7e4f2..5f2811c 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -12,13 +12,13 @@ foskym-oauth-center: clients: client_id: 应用 ID client_secret: 应用密钥 - redirect_uri: 回调地址(多地址请用空格分割) - grant_types: 授权类型(可空) - scope: 权限(可空) - client_name: 应用名称(可空) - client_desc: 应用描述(可空) - client_icon: 应用图标地址(可空 可使用fontawesome图标) - client_home: 主页地址(可空) + redirect_uri: 回调地址 + grant_types: 授权类型 + scope: 权限 + client_name: 名称 + client_desc: 描述 + client_icon: 图标 + client_home: 主页 add_button: 添加应用 forum: @@ -27,3 +27,5 @@ foskym-oauth-center: authorize: 授权 label: authorized: 授权记录 + authorize: + access: 授权访问 From 91a8f950ecc3dfdc27019db9e2c86c8aee87df18 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:23:03 +0800 Subject: [PATCH 13/35] feat: add model of scope --- js/src/common/extend.js | 4 +++- js/src/common/models/Scope.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 js/src/common/models/Scope.js diff --git a/js/src/common/extend.js b/js/src/common/extend.js index 54f41cd..8e49d35 100644 --- a/js/src/common/extend.js +++ b/js/src/common/extend.js @@ -1,7 +1,9 @@ import Extend from 'flarum/common/extenders'; import Client from "./models/Client"; +import Scope from "./models/Scope"; export default [ new Extend.Store() - .add('oauth-clients', Client), + .add('oauth-clients', Client) + .add('oauth-scopes', Scope), ]; diff --git a/js/src/common/models/Scope.js b/js/src/common/models/Scope.js new file mode 100644 index 0000000..2bf3eea --- /dev/null +++ b/js/src/common/models/Scope.js @@ -0,0 +1,9 @@ +import Model from 'flarum/common/Model'; + +export default class Client extends Model { + scope = Model.attribute('scope'); + is_default = Model.attribute('is_default', value => value === 1); + scope_name = Model.attribute('scope_name'); + scope_icon = Model.attribute('scope_icon'); + scope_desc = Model.attribute('scope_desc'); +} From bcddcfc468c25ee032916632100c71c276766fcf Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:41:17 +0800 Subject: [PATCH 14/35] feat(admin): add controller of scope --- extend.php | 7 +++- src/Api/Controller/CreateScopeController.php | 25 +++++++++++++ src/Api/Controller/DeleteScopeController.php | 28 +++++++++++++++ src/Api/Controller/ListScopeController.php | 23 ++++++++++++ src/Api/Controller/UpdateScopeController.php | 37 ++++++++++++++++++++ src/Api/Serializer/ScopeSerializer.php | 34 ++++++++++++++++++ 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 src/Api/Controller/CreateScopeController.php create mode 100644 src/Api/Controller/DeleteScopeController.php create mode 100644 src/Api/Controller/ListScopeController.php create mode 100644 src/Api/Controller/UpdateScopeController.php create mode 100644 src/Api/Serializer/ScopeSerializer.php diff --git a/extend.php b/extend.php index 2d24d6b..32bee83 100644 --- a/extend.php +++ b/extend.php @@ -33,7 +33,12 @@ return [ ->post('/oauth-clients', 'oauth.clients.create', Api\Controller\CreateClientController::class) ->get('/oauth-clients/{client_id}', 'oauth.clients.show', Api\Controller\ShowClientController::class) ->patch('/oauth-clients/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) - ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), + ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class) + + ->get('/oauth-scopes', 'oauth.clients.list', Api\Controller\ListClientController::class) + ->post('/oauth-scopes', 'oauth.clients.create', Api\Controller\CreateClientController::class) + ->patch('/oauth-scopes/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) + ->delete('/oauth-scopes/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), (new Extend\Settings) ->serializeToForum('foskym-oauth-center.allow_implicit', 'foskym-oauth-center.allow_implicit', 'boolval') diff --git a/src/Api/Controller/CreateScopeController.php b/src/Api/Controller/CreateScopeController.php new file mode 100644 index 0000000..e679155 --- /dev/null +++ b/src/Api/Controller/CreateScopeController.php @@ -0,0 +1,25 @@ +assertAdmin(); + + $attributes = Arr::get($request->getParsedBody(), 'data.attributes'); + + return Scope::create([]); + } +} diff --git a/src/Api/Controller/DeleteScopeController.php b/src/Api/Controller/DeleteScopeController.php new file mode 100644 index 0000000..ec2e22e --- /dev/null +++ b/src/Api/Controller/DeleteScopeController.php @@ -0,0 +1,28 @@ +getQueryParams(), 'id'); + RequestUtil::getActor($request) + ->assertAdmin(); + + $client = Scope::find($id); + + $client->delete(); + + return $client; + } +} diff --git a/src/Api/Controller/ListScopeController.php b/src/Api/Controller/ListScopeController.php new file mode 100644 index 0000000..44344ef --- /dev/null +++ b/src/Api/Controller/ListScopeController.php @@ -0,0 +1,23 @@ +assertAdmin(); + + return Scope::all(); + } +} diff --git a/src/Api/Controller/UpdateScopeController.php b/src/Api/Controller/UpdateScopeController.php new file mode 100644 index 0000000..d226d38 --- /dev/null +++ b/src/Api/Controller/UpdateScopeController.php @@ -0,0 +1,37 @@ +assertAdmin(); + + $id = Arr::get($request->getQueryParams(), 'id'); + $client = Scope::find($id); + + $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); + + collect(['scope', 'resource_path', 'method', 'is_default', 'scope_name', 'scope_icon', 'scope_desc']) + ->each(function (string $attribute) use ($client, $attributes) { + if (($val = Arr::get($attributes, $attribute)) !== null) { + $client->$attribute = $val; + } + }); + + $client->save(); + + return $client; + } +} diff --git a/src/Api/Serializer/ScopeSerializer.php b/src/Api/Serializer/ScopeSerializer.php new file mode 100644 index 0000000..fabdbc7 --- /dev/null +++ b/src/Api/Serializer/ScopeSerializer.php @@ -0,0 +1,34 @@ + $model->id, + "scope" => $model->scope, + "resource_path" => $model->resource_path, + "method" => $model->method, + "is_default" => $model->is_default, + "scope_name" => $model->scope_name, + "scope_icon" => $model->scope_icon, + "scope_desc" => $model->scope_desc, + ]; + } +} From 10bb43a6f0db23193d4f3c7d7583e705b6bf109b Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:41:37 +0800 Subject: [PATCH 15/35] feat(admin): scopes page --- js/dist/admin.js | Bin 8410 -> 10435 bytes js/dist/admin.js.map | Bin 25314 -> 31218 bytes js/dist/forum.js | Bin 6146 -> 6563 bytes js/dist/forum.js.map | Bin 20023 -> 21031 bytes js/src/admin/pages/ClientsPage.js | 3 - js/src/admin/pages/ScopesPage.js | 105 ++++++++++++++++++++++++++++-- less/admin.less | 2 +- locale/zh-Hans.yml | 9 +++ 8 files changed, 108 insertions(+), 11 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index 8a2bc57fc0ea55e7c83bcba7e4348f148cdd8d7b..c6c1a95fdd76ad98c5595aa5b9f511ef17889461 100644 GIT binary patch delta 1988 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k`zVINySd9A3CA8PwTxYC$^m86uyXsX#lc7z9iqUA zD=*7OyhWSA759C1D4Y|*`DKt<&x5bDz#U!QD9Z{WM6yH2v&*3}KzRxuAz&PBTo`rv zlvo!;P2!P%7JGmbC5;59sxh~*U$fsGu_T?&Eox&rn_HO~q(tuGfxN;46UB%ZLd#1d z3I1;fh0t+$U;S%rivw(Nu@7t~3$z-(MxpR$e?KW$Ov|0Xk@YR?yJ)cm^3&z$9=(WW ZtUu8&t3G`)Xmsll7OB?jmOp>RaSqG!&p7}9 diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index 5bf8831..b05e0af 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -1,10 +1,7 @@ import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; -import AdminPage from 'flarum/admin/components/AdminPage'; import Button from 'flarum/common/components/Button'; -import Client from "../../common/models/Client"; export default class ClientsPage extends Page { - settingName = 'collapsible-posts.reasons'; translationPrefix = 'foskym-oauth-center.admin.clients.'; clients = []; oninit(vnode) { diff --git a/js/src/admin/pages/ScopesPage.js b/js/src/admin/pages/ScopesPage.js index e830f7d..3f807c0 100644 --- a/js/src/admin/pages/ScopesPage.js +++ b/js/src/admin/pages/ScopesPage.js @@ -1,11 +1,102 @@ +import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; +import Button from 'flarum/common/components/Button'; +import Select from 'flarum/common/components/Select'; +import CheckBox from 'flarum/common/components/Checkbox'; export default class ScopesPage extends Page { - view() { - return ( -
-

Scopes Page

-
- ); - } + translationPrefix = 'foskym-oauth-center.admin.scopes.'; + scopes = []; + + oninit(vnode) { + super.oninit(vnode); + + this.fields = [ + 'scope', + 'resource_path', + 'method', + 'is_default', + 'scope_name', + 'scope_icon', + 'scope_desc' + ]; + + app.store.find('oauth-scopes').then(r => { + this.scopes = r; + this.fields.map(key => console.log(this.scopes[0][key])) + m.redraw(); + }); + } + + view() { + return ( +
+ { + m('.Form-group', [ + m('table', [ + m('thead', m('tr', [ + this.fields.map(key => m('th', app.translator.trans(this.translationPrefix + key))), + m('th'), + ])), + m('tbody', [ + this.scopes.map((scope, index) => m('tr', [ + this.fields.map(key => + m('td', key === 'method' ? Select.component({ + options: { + 'GET': 'GET', + 'POST': 'POST', + 'PUT': 'PUT', + 'DELETE': 'DELETE', + 'PATCH': 'PATCH', + }, + value: scope[key]() || 'GET', + onchange: (event) => { + this.saveScopeInfo(index, key, event.target.value); + }, + }) : key === 'is_default' ? CheckBox.component({ + state: scope[key]() || false, + onchange: (event) => { + this.saveScopeInfo(index, key, event.target.checked ? 1 : 0); + }, + }) : m('input.FormControl', { + type: 'text', + value: scope[key]() || '', + onchange: (event) => { + this.saveScopeInfo(index, key, event.target.value); + }, + })) + ), + m('td', Button.component({ + className: 'Button Button--icon', + icon: 'fas fa-times', + onclick: () => { + this.scopes[index].delete(); + this.scopes.splice(index, 1); + + }, + })), + ])), + m('tr', m('td', { + colspan: 7, + }, Button.component({ + className: 'Button Button--block', + onclick: () => { + const scope = app.store.createRecord('oauth-scopes'); + scope.save({}).then(this.scopes.push(scope)); + }, + }, app.translator.trans(this.translationPrefix + 'add_button')))), + ]), + ]), + ]) + } +
+ ); + } + + saveScopeInfo(index, key, value) { + console.log(index, key, value); + this.scopes[index].save({ + [key]: value, + }); + } } diff --git a/less/admin.less b/less/admin.less index 29341b2..7618a0e 100644 --- a/less/admin.less +++ b/less/admin.less @@ -29,7 +29,7 @@ max-width: 100% !important; } - .OAuthCenter-clientsPage { + .OAuthCenter-clientsPage, .OAuthCenter-scopesPage { table { width: 100%; diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index 5f2811c..e9a8d77 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -20,6 +20,15 @@ foskym-oauth-center: client_icon: 图标 client_home: 主页 add_button: 添加应用 + scopes: + scope: 权限标识 + resource_path: 资源路径 + method: 请求方法 + is_default: 默认 + scope_name: 名称 + scope_icon: 图标 + scope_desc: 描述 + add_button: 添加权限 forum: page: From 8bf8ab40abd693fcd1024ec29501107c7ba61f0a Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:43:01 +0800 Subject: [PATCH 16/35] fix: controller routes --- extend.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extend.php b/extend.php index 32bee83..824626c 100644 --- a/extend.php +++ b/extend.php @@ -35,10 +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) - ->get('/oauth-scopes', 'oauth.clients.list', Api\Controller\ListClientController::class) - ->post('/oauth-scopes', 'oauth.clients.create', Api\Controller\CreateClientController::class) - ->patch('/oauth-scopes/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) - ->delete('/oauth-scopes/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), + ->get('/oauth-scopes', 'oauth.scopes.list', Api\Controller\ListScopeController::class) + ->post('/oauth-scopes', 'oauth.scopes.create', Api\Controller\CreateScopeController::class) + ->patch('/oauth-scopes/{id}', 'oauth.scopes.update', Api\Controller\UpdateScopeController::class) + ->delete('/oauth-scopes/{id}', 'oauth.scopes.delete', Api\Controller\DeleteScopeController::class), (new Extend\Settings) ->serializeToForum('foskym-oauth-center.allow_implicit', 'foskym-oauth-center.allow_implicit', 'boolval') From 811957b46844b11328f890b2ee9c700096c7fee8 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:53:59 +0800 Subject: [PATCH 17/35] feat(admin): scope page --- js/dist/admin.js | Bin 10435 -> 10721 bytes js/dist/admin.js.map | Bin 31218 -> 32022 bytes js/dist/forum.js | Bin 6563 -> 6643 bytes js/dist/forum.js.map | Bin 21031 -> 21210 bytes js/src/admin/pages/ScopesPage.js | 16 ++++++++++++++-- src/Api/Controller/CreateScopeController.php | 4 +++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index c6c1a95fdd76ad98c5595aa5b9f511ef17889461..567e5fe6c2e417e61a445d06923c0cfa1bbc3e08 100644 GIT binary patch delta 234 zcmX>c_%L__JDYb=YH@yPQF3a0L1IaUZKj5%USdf}QD#zUNvehtilmaJPO4sRYDq?Z z3c5Oo=w>FiJSN8A$%Pyy>=m{pdU+bbo7Zq;bFx-wXlmq7mJ?a9d5=&mBV)y8DUr|Y zT)to>u9`Yolew9vZeAlZlbO+XvICFE<|u{7j0(lc`30#~O2HsXPf5E(uP8AuB|kS9 z=(xOe4GYc5wo1v9cS*@HT1>trHF@$9r9?(Ipg~fb6_n4jFlJ5upgsvG(5&GA06w@+ AWB>pF delta 120 zcmaDDd^m6eJKN@PwoE3*ipd8#OxS~MOZ4(IDmMS&$mV1X*3i_*pPVPMU^9@sLV#4H5l|!~=#oVdYQzdESg=6?35iXYELebqM1c*e)QXw=+{RwCs_Mn_eRt;0 zoS8W@_x zK)vWW73FDBhV3WuSge(;!VN75Re-t#*t)Jy&uo`ZzRHnAynnHpkZ)y*Y_EGe?^wnjM#<6DR^ zK@XOLTc&p>3p)B_K9UCJ(=*q1s{@Znj)+ zu1Le783?ytp32LUArgmXH98oIs#{p1Ev{~30*V5?;%*opV%J-Qd#%^o>JGuDhr7%* zN)@T(fIkjzKhb(hLnm6z!Mv}y|4!SA(l&2IBg^Q9yJp`k?&wUfa9M$I2`ED4p&W`; zMgT)zN>0qsO!95~YVC{;S4=jpJJ_S2n$88uNW-5~L5v)kkPj3{t*ySlN z-0m84Y)Zm~w&Y(}r({MdKFZ*vASCqAPtSp=`~GNFre*~>PBk0nY8?BQlsr5wMG2mP z6Fs9!0U|vXrMRE$Iihq_J;W*82x=oQ;XRABy=EWbY{6HSF>^LRTH&~KP=wzt)5vH*#6g$3in73Wuk|c$`{4AvSpsvnyu+TSXF34<1LR2InZq_M1h77aKn?{or z;b#B5qn;H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.scopes.push(scope)); + scope.save({ + 'scope': 'Scope.' + this.randomString(8), + }).then(this.scopes.push(scope)); }, }, app.translator.trans(this.translationPrefix + 'add_button')))), ]), @@ -92,7 +94,17 @@ export default class ScopesPage extends Page {
); } - + randomString(len) { + len = len || 8; + let $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let maxPos = $chars.length; + let str = ''; + for (let i = 0; i < len; i++) { + //0~32的整数 + str += $chars.charAt(Math.floor(Math.random() * (maxPos + 1))); + } + return str; + } saveScopeInfo(index, key, value) { console.log(index, key, value); this.scopes[index].save({ diff --git a/src/Api/Controller/CreateScopeController.php b/src/Api/Controller/CreateScopeController.php index e679155..df0ef23 100644 --- a/src/Api/Controller/CreateScopeController.php +++ b/src/Api/Controller/CreateScopeController.php @@ -20,6 +20,8 @@ class CreateScopeController extends AbstractListController $attributes = Arr::get($request->getParsedBody(), 'data.attributes'); - return Scope::create([]); + return Scope::create([ + 'scope' => Arr::get($attributes, 'scope'), + ]); } } From 3b5354c4aff5e3c7d916673123b2800af62acaee Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 19:54:19 +0800 Subject: [PATCH 18/35] fix: scope model --- js/src/common/models/Scope.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/src/common/models/Scope.js b/js/src/common/models/Scope.js index 2bf3eea..97810b7 100644 --- a/js/src/common/models/Scope.js +++ b/js/src/common/models/Scope.js @@ -2,6 +2,8 @@ import Model from 'flarum/common/Model'; export default class Client extends Model { scope = Model.attribute('scope'); + resource_path = Model.attribute('resource_path'); + method = Model.attribute('method'); is_default = Model.attribute('is_default', value => value === 1); scope_name = Model.attribute('scope_name'); scope_icon = Model.attribute('scope_icon'); From bd1c7f36bb1c5262581887d80552e22ddfeb3761 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 20:30:49 +0800 Subject: [PATCH 19/35] fix: controller class --- src/Api/Controller/CreateClientController.php | 4 ++-- src/Api/Controller/CreateScopeController.php | 4 ++-- src/Api/Controller/DeleteClientController.php | 8 +++----- src/Api/Controller/DeleteScopeController.php | 13 +++++-------- src/Api/Controller/ShowClientController.php | 4 ++-- src/Api/Controller/UpdateScopeController.php | 14 +++++++------- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Api/Controller/CreateClientController.php b/src/Api/Controller/CreateClientController.php index f1b7b2c..866b73b 100644 --- a/src/Api/Controller/CreateClientController.php +++ b/src/Api/Controller/CreateClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractCreateController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; -class CreateClientController extends AbstractListController +class CreateClientController extends AbstractCreateController { public $serializer = ClientSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/CreateScopeController.php b/src/Api/Controller/CreateScopeController.php index df0ef23..014d45d 100644 --- a/src/Api/Controller/CreateScopeController.php +++ b/src/Api/Controller/CreateScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractCreateController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class CreateScopeController extends AbstractListController +class CreateScopeController extends AbstractCreateController { public $serializer = ScopeSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/DeleteClientController.php b/src/Api/Controller/DeleteClientController.php index 17907d0..e585dfa 100644 --- a/src/Api/Controller/DeleteClientController.php +++ b/src/Api/Controller/DeleteClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractDeleteController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,10 +10,10 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; -class DeleteClientController extends AbstractListController +class DeleteClientController extends AbstractDeleteController { public $serializer = ClientSerializer::class; - protected function data(ServerRequestInterface $request, Document $document) + protected function delete(ServerRequestInterface $request) { $id = Arr::get($request->getQueryParams(), 'id'); RequestUtil::getActor($request) @@ -22,7 +22,5 @@ class DeleteClientController extends AbstractListController $client = Client::find($id); $client->delete(); - - return $client; } } diff --git a/src/Api/Controller/DeleteScopeController.php b/src/Api/Controller/DeleteScopeController.php index ec2e22e..52729d8 100644 --- a/src/Api/Controller/DeleteScopeController.php +++ b/src/Api/Controller/DeleteScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractDeleteController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,19 +10,16 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class DeleteScopeController extends AbstractListController +class DeleteScopeController extends AbstractDeleteController { - public $serializer = ScopeSerializer::class; - protected function data(ServerRequestInterface $request, Document $document) + protected function delete(ServerRequestInterface $request) { $id = Arr::get($request->getQueryParams(), 'id'); RequestUtil::getActor($request) ->assertAdmin(); - $client = Scope::find($id); + $scope = Scope::find($id); - $client->delete(); - - return $client; + $scope->delete(); } } diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 5a64375..784736f 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractShowController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer; -class ShowClientController extends AbstractListController +class ShowClientController extends AbstractShowController { public $serializer = ClientPublicSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/UpdateScopeController.php b/src/Api/Controller/UpdateScopeController.php index d226d38..5f9aeb7 100644 --- a/src/Api/Controller/UpdateScopeController.php +++ b/src/Api/Controller/UpdateScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractShowController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class UpdateScopeController extends AbstractListController +class UpdateScopeController extends AbstractShowController { public $serializer = ScopeSerializer::class; protected function data(ServerRequestInterface $request, Document $document) @@ -19,19 +19,19 @@ class UpdateScopeController extends AbstractListController $actor->assertAdmin(); $id = Arr::get($request->getQueryParams(), 'id'); - $client = Scope::find($id); + $scope = Scope::find($id); $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); collect(['scope', 'resource_path', 'method', 'is_default', 'scope_name', 'scope_icon', 'scope_desc']) - ->each(function (string $attribute) use ($client, $attributes) { + ->each(function (string $attribute) use ($scope, $attributes) { if (($val = Arr::get($attributes, $attribute)) !== null) { - $client->$attribute = $val; + $scope->$attribute = $val; } }); - $client->save(); + $scope->save(); - return $client; + return $scope; } } From 8a23f8ddf0678a53a589127b2283af77a7aecd0b Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:09:21 +0800 Subject: [PATCH 20/35] fix: scope page --- js/src/admin/pages/ScopesPage.js | 17 +++++++++-------- js/src/common/models/Scope.js | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/js/src/admin/pages/ScopesPage.js b/js/src/admin/pages/ScopesPage.js index 3a137bb..2bf51c7 100644 --- a/js/src/admin/pages/ScopesPage.js +++ b/js/src/admin/pages/ScopesPage.js @@ -2,7 +2,7 @@ import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; import Button from 'flarum/common/components/Button'; import Select from 'flarum/common/components/Select'; -import CheckBox from 'flarum/common/components/Checkbox'; +import Checkbox from 'flarum/common/components/Checkbox'; export default class ScopesPage extends Page { translationPrefix = 'foskym-oauth-center.admin.scopes.'; @@ -50,18 +50,20 @@ export default class ScopesPage extends Page { 'PATCH': 'PATCH', }, value: scope[key]() || 'GET', - onchange: (event) => { - this.saveScopeInfo(index, key, event.target.value); + onchange: (value) => { + this.saveScopeInfo(index, key, value); }, - }) : key === 'is_default' ? CheckBox.component({ - state: scope[key]() || false, - onchange: (event) => { - this.saveScopeInfo(index, key, event.target.checked ? 1 : 0); + }) : key === 'is_default' ? Checkbox.component({ + state: scope[key]() === 1 || false, + onchange: (checked) => { + this.scopes[index].is_default((this.scopes[index].is_default() + 1) % 2) + this.saveScopeInfo(index, key, checked ? 1 : 0); }, }) : m('input.FormControl', { type: 'text', value: scope[key]() || '', onchange: (event) => { + this.saveScopeInfo(index, key, event.target.value); }, })) @@ -106,7 +108,6 @@ export default class ScopesPage extends Page { return str; } saveScopeInfo(index, key, value) { - console.log(index, key, value); this.scopes[index].save({ [key]: value, }); diff --git a/js/src/common/models/Scope.js b/js/src/common/models/Scope.js index 97810b7..2b89440 100644 --- a/js/src/common/models/Scope.js +++ b/js/src/common/models/Scope.js @@ -1,10 +1,10 @@ import Model from 'flarum/common/Model'; -export default class Client extends Model { +export default class Scope extends Model { scope = Model.attribute('scope'); resource_path = Model.attribute('resource_path'); method = Model.attribute('method'); - is_default = Model.attribute('is_default', value => value === 1); + is_default = Model.attribute('is_default'); scope_name = Model.attribute('scope_name'); scope_icon = Model.attribute('scope_icon'); scope_desc = Model.attribute('scope_desc'); From 663828aaf76eb51bc472665b9e874d2649af4aa2 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:09:46 +0800 Subject: [PATCH 21/35] feat: authorize page --- js/dist/admin.js | Bin 10721 -> 10705 bytes js/dist/admin.js.map | Bin 32022 -> 32032 bytes js/dist/forum.js | Bin 6643 -> 7223 bytes js/dist/forum.js.map | Bin 21210 -> 23797 bytes .../forum/components/oauth/AuthorizePage.js | 292 +++++++++++------- less/admin.less | 4 + less/forum/oauth.less | 12 +- locale/zh-Hans.yml | 2 + 8 files changed, 200 insertions(+), 110 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index 567e5fe6c2e417e61a445d06923c0cfa1bbc3e08..5ecd5a14bc40c5397206e56b141b0f8928da3af7 100644 GIT binary patch delta 92 zcmaDDd@*=K4cq1!Y_}vQ*DGkV7~0y}PF|&;Y?7Q`kXjs_7ps?99G{Y!mROooqM=cu fSBy93vwQ~H8IuYb5tCXVCzFLBBa=oU8V6%& gWn*h)WV7)g^a7K@8yE$1V{dR}li(X8vl1k~1+kzR(*OVf diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map index b06d6b77fb19336f941646582caaae430f7ca68e..308bcfe179d1017762437e2a89f25eb068c1f66b 100644 GIT binary patch delta 668 zcmZ`$OK1~O6lI#vw1tQS5fd?)QYwvkwn+>5C_&zP8N(PPV`G}uQrl!QX{HJ3G?QQ= zmg3%pa6$YaxDz*i7;q)x!cCWMUAYmZAn3Lr_};^%ZtlHs&pYSb^Bx>Y&yJ+muY5BV zq+(n|WsGr;paN@R-X%!m^EFm%0-tm8W%rlcY4`jrU=GBDmEEAZGK9(VX2 zmv6v3|0y^ruN_k{P0|EGRg7yb0ypK;7du4fdU%0|CKO9;!iXqWql{mSCF=@IDzt5okTY_er^eDG;b&>K5wm1__6YDZhqQVOuKh@N`O( z7Ts@C3Gay&5eLc;j9Cg*c1phL#?QV8`pU+RZNlfwd-rAb;k2i|GlaXB6xUkc^TCEX z34>+`J~YSSiW!1~wE*my2y7!N)#1Kz!I#VBlq4J&=Vha18f~)yb~D28f!vzaZJ5LL zIm_8-n9bUt)1RH~w=8GQ;eyUT)-ffnBxA~qvJit`^(+(`Us>OWCzV6^x#@QwHHTg| X)qWfBa?kL6xasO6$-|s1-TC+jIZ@Jk delta 570 zcmX|-&ubG=5XV{5Y}-RUgi=btWP@O!KB7^KQHVHiHYrPyO-Pg2CQ8G0iK)`mxW*`g zKdy?P1I0_B9xGS_?<`&f{{j*5Xbe7wjb(Zs zdO6{?rEsCRMmaNMJfXm}COcAi04-UiEi*cCpX*S*Nng!b`9O*qKyz6*ppU39#;_;K z`kj_y9$1gLR{n#%*;${!C{MTq6My=N4*eqhDE^}C35(}8$ zK<$Qk?&auShyEo%8%HV8k^pUanJ2)m%!~*}_&lH{u(;0ta8_PK;i@0wgUI-!`Kq3@ zuU<#vA+ycqNPDpi{W_IQx?N=a2Gal)9b-?n3;fFpUwF*VMf6TehYUCjUb5*!tZ1Ox zi*21S&e50IByA>aBdvZX&W}xxcISw!o;Sp?1Lc3XasqG0te4HpxvQSbcSFukeI(SPqGeXpl!#}#UDw=hNf{YJR#bvAredps7> JO&d?Y9RTvjwPFAO diff --git a/js/dist/forum.js b/js/dist/forum.js index 125dc0075042fa35013b25c1216e2dcff7091fd9..4ee4e8b5f13846242eb843c7018a12a07036a300 100644 GIT binary patch delta 2252 zcmb7FJ!~9B6qfPD7n|5zV*6qz5S^EBnT_Yxb_gi!Y3&F_g36AF5kiS|+S{GG-FW|) znYDefPDf8UMJgZ#1yTx-D3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fR6&}8bSg_Siuz+6fmqQ0(9P`ct_jkKnw?u0#yIY)-@uJPSsbc^(XaU z7e4<}Z>W1~<7%oGmjB7-RdhmFHtcUkW&_Js`b=0jb~kLJzscP+W8VPmTd2Tp#i|pl zDQfQ7)MqP<#yqiruQ1>XhaMS@4EEXRJ+q9SwC9m>m^Q3#uneDQP#`)qEir#S_2N`= z`bzS{_meNZtlhYL@#|;LBtDr>&AgnvGMhXzqosawDlvEJ#^w31U%#9>|KqRUcAxEu;7lhpEqQu2acw?%jgrruPQ8CIb?!MlUVruN z8`GDPbFX6Y*Ns=+7xOz2l?KOBzTs>>02`|WqIFBdMJxt`{ z`$qegWvlXO{aTt6d0WHYVZSe?4S4pJ9L1Fv@u+_crAeb9oB1PJ;m{VmX6k!OnRWy9 z^ws2chlG?g*fKGLAW8u>yWAlZQsa2whyVuK*NT_KEq6sj2C& zCZ|&8CP8WP`L|P(Q`g^n?sge-PiA^^gR`9eE_W*2pEm8H3(n2ieKsFv6@3blzG%py zkZUKcYP!qTXDjl1WQQ-*-#O}ZgsTo58)@6u)79(f>57;KeU1LHB_^Jx0SsV&O<3vsmbf$A$`ho?y`H@f}{`4A6tS&MI7@FAi0}Jc4@Z@{K6~Ouby8%@Z!S1 z*}OeH^fWZX4*a*^zlr|XyfNFF=Cglly|{*`r*CyT6Hb5bDWTTh&nS54K{|J6e?I4J U(`|u%T$nH1LY@&nb@g5NA88x app.modal.show(LogInModal), 500); - } + oninit(vnode) { + super.oninit(vnode); + if (!app.session.user) { + setTimeout(() => app.modal.show(LogInModal), 500); + } - const params = m.route.param(); + const params = m.route.param(); - if (params.client_id == null || params.response_type == null || params.redirect_uri == null) { - m.route.set('/'); + if (params.client_id == null || params.response_type == null || params.redirect_uri == null) { + m.route.set('/'); + } else { + this.params = params; + app.store.find('oauth-clients', params.client_id).then(client => { + if (client.length === 0) { + m.route.set('/'); } else { - this.params = params; - app.store.find('oauth-clients', params.client_id).then(client => { - if (client.length === 0) { - m.route.set('/'); - } else { - this.client = client[0]; - let uris = null; - if (this.client.redirect_uri().indexOf(' ') > -1) { - uris = this.client.redirect_uri().split(' '); - } else { - uris = [this.client.redirect_uri()]; - } + this.client = client[0]; + let uris = null; + if (this.client.redirect_uri().indexOf(' ') > -1) { + uris = this.client.redirect_uri().split(' '); + } else { + uris = [this.client.redirect_uri()]; + } - 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('/'); - } - } + 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('/'); + } + + app.store.find('oauth-scopes').then((scopes) => { + this.scopes = scopes + let scope = params.scope; + + if (params.scope == null) { + scope = this.client.scope(); + } + + let scopes_temp = []; + if (scope == null) { + scopes_temp = []; + } else if (scope.indexOf(' ') > -1) { + scopes_temp = scope.split(' '); + } else { + scopes_temp = [scope]; + } + + let default_scopes = []; + this.scopes.map(scope => { + if (scope.is_default() === 1) { + default_scopes.push(scope); + } }); + + scopes_temp = scopes_temp.concat(default_scopes); + + this.client_scope = scopes_temp.filter((scope, index) => scopes_temp.indexOf(scope) === index); + console.log( this.client_scope ); + this.loading = false; + m.redraw(); + }); + + } + }); } + } - setTitle() { - app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize'))); - app.setTitleCount(0); + setTitle() { + app.setTitle(extractText(app.translator.trans('foskym-oauth-center.forum.page.title.authorize'))); + app.setTitleCount(0); + } + + view() { + if (!this.client) { + return ''; } + return ( + !this.loading &&

+
+
+
+
+

{app.forum.attribute('title')}

+

+ {app.translator.trans('foskym-oauth-center.forum.authorize.access')} {this.client.client_name()} +

- view() { - if (!this.client) { - return ''; - } - return ( -
-
-
-
-
-

{app.forum.attribute('title')}

-

- {app.translator.trans('foskym-oauth-center.forum.authorize.access')} {this.client.client_name()} -

+
+
-
-
- -
- - - - - -
-
-
-
- -
-
-
- 保持对已向 计量便民平台 授予访问权限的数据的访问权限
- - 即使当前没有使用该应用,也允许 计量便民平台 查看和更新你授予其访问权限的数据。这不会向 - 计量便民平台 授予任何其他权限。 -
-
-
-
- -
-
-
- 读取用户个人资料
- - 访问该用户(mouse123)的个人信息、最新动态等 -
-
-
-
- - - - - -
- - -
-
- - -
-
-
+
+ + + + +
+
+ { + this.client_scope.length > 0 && this.client_scope.map(scope => { + let scope_info = null; + this.scopes.map(s => { + if (s.scope() === scope.scope()) { + scope_info = s; + } + }); + if (scope_info == null) { + return ''; + } + return ( +
+
+ { + (scope_info.scope_icon().indexOf('fa-') > -1) ? + : + + } +
+
+
+ {scope_info.scope_name()} +
+ + { + scope_info.scope_desc() + .replace('{client_name}', this.client.client_name()) + .replace('{user}', app.session.user.attribute('displayName')) + } + +
+
+ ); + }) + } +
+
+{/* + + + + */} + +
+ + +
+
+ + +
- ); - } +
+
+
+ ); + } + + onsubmit(e) { + e.preventDefault(); + app.request({ + method: 'POST', + url: '/oauth/authorize', + body: { + response_type: this.params.response_type, + client_id: this.params.client_id, + redirect_uri: this.params.redirect_uri, + state: this.params.state, + scope: this.params.scope, + is_authorized: this.is_authorized, + } + }).then((r) => console.log(r)); + + // Some form handling logic here + } } diff --git a/less/admin.less b/less/admin.less index 7618a0e..8add5d6 100644 --- a/less/admin.less +++ b/less/admin.less @@ -42,6 +42,10 @@ } } + .Checkbox { + padding: 0 10px; + } + .FormControl { background: @body-bg; border-color: @control-bg; diff --git a/less/forum/oauth.less b/less/forum/oauth.less index b76de17..c85eea5 100644 --- a/less/forum/oauth.less +++ b/less/forum/oauth.less @@ -13,6 +13,8 @@ width: 376px; margin: 0 auto; box-sizing: border-box; + box-shadow: 0px 0px 15px 0px #bdbdbd; + border-radius: 12px; } .oauth-main::before { @@ -23,8 +25,8 @@ height: 100%; left: 0; top: 0; - box-shadow: 0 25px 50px #00000030; background: hsla(0, 0%, 100%, .3); + border-radius: 12px; } .oauth-box { @@ -36,6 +38,7 @@ backdrop-filter: blur(0); text-align: center; box-shadow: 0 5px 10px -5px #d2d2d2; + border-radius: 12px 12px 0 0; } .oauth-header h2 { @@ -51,6 +54,10 @@ color: #333; } +.oauth-body { + border-radius: 0 0 12px 12px; +} + .oauth-body .oauth-form-item { position: relative; margin-bottom: 15px; @@ -100,7 +107,7 @@ label:before { } .oauth-header { - background-color: #fff; + // background-color: #fff; } body { @@ -209,6 +216,7 @@ img.oauth-scope-object { margin-top: 0; font-weight: 800; color: #382e2e; + margin-block-end: 0; } .oauth-scope-body small { diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index e9a8d77..556fb1b 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -38,3 +38,5 @@ foskym-oauth-center: authorized: 授权记录 authorize: access: 授权访问 + agree: 授权 + deny: 拒绝 From f76763496ac714eeaca295c4910caee035bab207 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:10:09 +0800 Subject: [PATCH 22/35] fix: client info --- src/Api/Controller/ShowClientController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 784736f..5a64375 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractShowController; +use Flarum\Api\Controller\AbstractListController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer; -class ShowClientController extends AbstractShowController +class ShowClientController extends AbstractListController { public $serializer = ClientPublicSerializer::class; protected function data(ServerRequestInterface $request, Document $document) From 19a17bc8513522bbca5a8e6ee6b8e4c89f334a32 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:10:21 +0800 Subject: [PATCH 23/35] fix: oauth --- src/Controllers/AuthorizeController.php | 9 +++++---- src/Storage.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Controllers/AuthorizeController.php b/src/Controllers/AuthorizeController.php index e210b87..c1a8f6a 100644 --- a/src/Controllers/AuthorizeController.php +++ b/src/Controllers/AuthorizeController.php @@ -35,14 +35,14 @@ class AuthorizeController implements RequestHandlerInterface $params = $request->getParsedBody(); - $oauth = new OAuth(); + $oauth = new OAuth($this->settings); $server = $oauth->server(); $request = $oauth->request()::createFromGlobals(); $response = $oauth->response(); if (!$server->validateAuthorizeRequest($request, $response)) { - $response->send(); - die; + $response->getResponseBody(); + return new JsonResponse(json_decode($response->getResponseBody(), true)); } $is_authorized = (Arr::get($params, 'authorized', 'no') === 'yes'); @@ -52,6 +52,7 @@ class AuthorizeController implements RequestHandlerInterface /* $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); exit("SUCCESS! Authorization Code: $code");*/ } - $response->send(); + $response->getResponseBody(); + return new JsonResponse(json_decode($response->getResponseBody(), true)); } } diff --git a/src/Storage.php b/src/Storage.php index e99fea1..ba93f38 100644 --- a/src/Storage.php +++ b/src/Storage.php @@ -433,7 +433,7 @@ class Storage implements if ($result = Models\Scope::where('is_default', true)->get()) { $defaultScope = array_map(function ($row) { return $row['scope']; - }, $result); + }, $result->toArray()); return implode(' ', $defaultScope); } From 6e2aeffb4305258980ade5ae9411458c1effcf8b Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:28:20 +0800 Subject: [PATCH 24/35] fix: authorize --- js/dist/forum.js | Bin 7223 -> 7383 bytes js/dist/forum.js.map | Bin 23797 -> 24182 bytes .../forum/components/oauth/AuthorizePage.js | 27 +++++++++++------- src/Controllers/AuthorizeController.php | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 4ee4e8b5f13846242eb843c7018a12a07036a300..319120c1608426433c586c27ebbaf42bd46a8aed 100644 GIT binary patch delta 309 zcmdmPaouu5GZSOxB}EoHCQYG6^vzZsuUN1`2O>Vco|Fq?p;)F^lOHmnP+A zmc-}eC#GcPrQ0eR>ZI0YZr;rGmKkWkLOvtOOud5A;tY)v&00-Oojlt-z2yA7lX(SgCYOne z27+v{O)JeyF3HT#1G=ReY*>9sofdSLSjDmB>LEa~kMoHCQYG6^weZsuUN1`2O>Vco|Fq?p;)F*DUBZa&WS zmKmscE1!{MqFzC1afU{TX04{CPM&R^UUGh3a$<=_;wJtH?1Gua@rk7+8Tmz-RjDbq qiiWk56$Py)e-}$cmoWgz*i1esF1lG;Vj9q{$;Y`&Hh+_R$OHh-NHsM8 diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index e7f62edec2158ae4a6ce02f2c08c48421bc4f4ed..faae6328c5aa2d45368305ed0101e862c7199214 100644 GIT binary patch delta 2680 zcma)8&rf4j6i(GR%mDKX7{EA_4v9K5Jb{)DKb&D^?z`{xQ66tzp_E$0OrR~L&=zP5 zG9{D#14d15;>MM()Qu)xIWbP$=t7Mvm%4Ff)TJ61CVuDKjstOG+_d!G^Yi<@b1uJq z68Qboz{kzw$NWXZ7xARJfBeHGTgZyJBaOT%M8Py{A>4{Iq!0oh@noD%#FpeQX*dGD zF`Uft!2*94Eh8yPUd2SzvbSS~Egai5_5O*0i!ZZ9nJk1Cv0x#*kY%_+Ncs?A_4A3@ zwl%U!z4xUeSK-%8BPGO`G&~{p&8j{unMO{CyhVq5W?3KNYXx1{CG}?edBJ6f zgg{7{O>wb;%#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8Fr~<}dAZ6Y;-~9({lMO>;;1 zP1rfr{bcdyBj&6Qn(@rIxtk0axj1TmSI5jl_d)+;qmEp~>IHK~hs;tY^n%CRMy7x4 SHZpRc`@_{=edeoc5B~wIrFIwq diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index ec1e0a5..02a757d 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -14,6 +14,7 @@ export default class AuthorizePage extends IndexPage { client_scope = []; loading = true; is_authorized = false; + submit_loading = false; oninit(vnode) { super.oninit(vnode); @@ -76,7 +77,7 @@ export default class AuthorizePage extends IndexPage { scopes_temp = scopes_temp.concat(default_scopes); this.client_scope = scopes_temp.filter((scope, index) => scopes_temp.indexOf(scope) === index); - console.log( this.client_scope ); + console.log(this.client_scope); this.loading = false; m.redraw(); }); @@ -135,9 +136,9 @@ export default class AuthorizePage extends IndexPage {
{ (scope_info.scope_icon().indexOf('fa-') > -1) ? - : - + : + }
@@ -158,7 +159,7 @@ export default class AuthorizePage extends IndexPage { }
-{/* + {/* @@ -166,14 +167,12 @@ export default class AuthorizePage extends IndexPage { */}
- -
@@ -187,6 +186,12 @@ export default class AuthorizePage extends IndexPage {
); } + deny(e) { + this.is_authorized = false; + } + agree(e) { + this.is_authorized = true; + } onsubmit(e) { e.preventDefault(); diff --git a/src/Controllers/AuthorizeController.php b/src/Controllers/AuthorizeController.php index c1a8f6a..325b614 100644 --- a/src/Controllers/AuthorizeController.php +++ b/src/Controllers/AuthorizeController.php @@ -45,7 +45,7 @@ class AuthorizeController implements RequestHandlerInterface return new JsonResponse(json_decode($response->getResponseBody(), true)); } - $is_authorized = (Arr::get($params, 'authorized', 'no') === 'yes'); + $is_authorized = Arr::get($params, 'is_authorized', 0); $server->handleAuthorizeRequest($request, $response, $is_authorized, $actor->id); if ($is_authorized) { // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client From b7d78c0af41b73501a692c705583115b199fb518 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:36:18 +0800 Subject: [PATCH 25/35] fix: authorize --- src/Storage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Storage.php b/src/Storage.php index ba93f38..c5c26c9 100644 --- a/src/Storage.php +++ b/src/Storage.php @@ -204,10 +204,10 @@ class Storage implements */ public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null, $id_token = null, $code_challenge = null, $code_challenge_method = null) { - if (func_num_args() > 6) { + /*if (func_num_args() > 6) { // we are calling with an id token return call_user_func_array(array($this, 'setAuthorizationCodeWithIdToken'), func_get_args()); - } + }*/ // convert expires to datestring $expires = date('Y-m-d H:i:s', $expires); From c70c2ae8a165e7e68a8dd4769fc4d59f21791208 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:36:27 +0800 Subject: [PATCH 26/35] fix: authorize --- js/dist/forum.js | Bin 7383 -> 7482 bytes js/dist/forum.js.map | Bin 24182 -> 24576 bytes .../forum/components/oauth/AuthorizePage.js | 9 ++++++++- src/Controllers/AuthorizeController.php | 6 ++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 319120c1608426433c586c27ebbaf42bd46a8aed..d5bc252c77ffaa5bbf767791667ca5a15e31dcfd 100644 GIT binary patch delta 157 zcmWm3F$%&k6o6sG(F@ecl0gzuvTF$T1cGxZ5^8Fn=zHZgwNr8PJVG}w;&r6s|NXz+ zcmK(g)zfntTx_7TQ=V)VuNlY{rLBqO9Gn8CQITo;u92*T6FL@LDm!0v!L*+Jqca>X zz@dugo{B(^H&CS;(lbHb{X%0yM diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index faae6328c5aa2d45368305ed0101e862c7199214..47f846962e9f66fdfb0f8e9b8ac1caae38b8c183 100644 GIT binary patch delta 862 zcmX|;&rcIU6vtCy41tp|^j88*umKt;g(3uqDfo6eUCUZ3wuK-zwo#zlmff;#A=)(P z)ti}RcUSuy;h1z`$_C&8-}kpgB7o!j`XkT>M<~gbW(G`z`s=C?o*iur z4-4uw9=d4_vZ6kPZ&_{0cSyMhLL#M*t2%xlVr$9ZC4drd7+~TZ(N7G?h;sK>Xvi$L zgtdbBYBI7mfmtGFj-TM;Z3~j`H8ZLnnHq7WdJ{1NXX;1f-t4k=%Xt_Uh%HP{0KO~X z18NWj!;u}e7M-4WAqlsHQPX=D^?I(F(eOx8svE(ZgLhGH^`cevsweF@OKq^;6Nl+v z^RUCJp2t$`pzPO}cKrI&PR(vFtB>XQ3|h_bnFjvJ5I;i?-1si)XZihqAUgN1 delta 466 zcmX9)%}T>S5GGzMdhw68Nl`08P`X%K)S83V$z&Tf#HzLQSgMHD{zM~+Er`B?%vJCO zJQOOPJopNI55b!^!QJ(;J3F)A-#mV5KOb7}btKaALz@+$-G3YT9Ua4cU>txWtJ{Eu zOBzI{wGMqpW12<7v7?!*0`mciIbs}e)b5CFuH@x@fsrE7YOFAZ4*>ctatSyv(immmbm0cl5d*8i_AeZ|el z+W#X%hHge04l4jGCk|@A zjM;R+rMGfMDSAh0g)J^2T}Lg{XE!$RLj?&rjYlW@*+iI|3Kx?bo5_=)eH}DUmzu%Z TLb%v}C_RmmUNyClYSouNur`DA diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index 02a757d..bc87b36 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -206,7 +206,14 @@ export default class AuthorizePage extends IndexPage { scope: this.params.scope, is_authorized: this.is_authorized, } - }).then((r) => console.log(r)); + }).then((params) => { + let arr = [] + for (let k in params) { + arr.push(`${k}=${params[k]}`) + } + let url = `${this.params.redirect_uri }?${arr.join('&')}`; + window.location.href = url; + }); // Some form handling logic here } diff --git a/src/Controllers/AuthorizeController.php b/src/Controllers/AuthorizeController.php index 325b614..96902af 100644 --- a/src/Controllers/AuthorizeController.php +++ b/src/Controllers/AuthorizeController.php @@ -49,8 +49,10 @@ class AuthorizeController implements RequestHandlerInterface $server->handleAuthorizeRequest($request, $response, $is_authorized, $actor->id); if ($is_authorized) { // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client - /* $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); - exit("SUCCESS! Authorization Code: $code");*/ + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); + return new JsonResponse([ + 'code' => $code + ]); } $response->getResponseBody(); return new JsonResponse(json_decode($response->getResponseBody(), true)); From cde2367103677f277ac671ca5fa20e261b652d87 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 03:20:41 +0800 Subject: [PATCH 27/35] fix: authorize --- js/dist/forum.js | Bin 7482 -> 7505 bytes js/dist/forum.js.map | Bin 24576 -> 24629 bytes .../forum/components/oauth/AuthorizePage.js | 1 + 3 files changed, 1 insertion(+) diff --git a/js/dist/forum.js b/js/dist/forum.js index d5bc252c77ffaa5bbf767791667ca5a15e31dcfd..f4ad0d6a20adbf77ed341c38341668ac4f6ee250 100644 GIT binary patch delta 20 bcmdmGb Date: Mon, 2 Oct 2023 03:37:57 +0800 Subject: [PATCH 28/35] feat: unset csrf in oauth --- extend.php | 7 ++++- src/Controllers/AuthorizeController.php | 4 +-- src/Middlewares/ResourceScopeMiddleware.php | 12 +++++-- src/Middlewares/UnsetCsrfMiddleware.php | 35 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/Middlewares/UnsetCsrfMiddleware.php diff --git a/extend.php b/extend.php index 824626c..c3ec7d9 100644 --- a/extend.php +++ b/extend.php @@ -12,7 +12,9 @@ namespace FoskyM\OAuthCenter; use Flarum\Extend; +use Flarum\Http\Middleware\CheckCsrfToken; use FoskyM\OAuthCenter\Middlewares\ResourceScopeMiddleware; +use FoskyM\OAuthCenter\Middlewares\UnsetCsrfMiddleware; return [ (new Extend\Frontend('forum')) @@ -26,7 +28,8 @@ return [ new Extend\Locales(__DIR__.'/locale'), (new Extend\Routes('forum')) - ->post('/oauth/authorize', 'oauth.authorize.post', Controllers\AuthorizeController::class), + ->post('/oauth/authorize', 'oauth.authorize.post', Controllers\AuthorizeController::class) + ->post('/oauth/token', 'oauth.token', Controllers\TokenController::class), (new Extend\Routes('api')) ->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class) @@ -45,5 +48,7 @@ return [ ->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('forum')) + ->insertBefore(CheckCsrfToken::class, UnsetCsrfMiddleware::class), (new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class), ]; diff --git a/src/Controllers/AuthorizeController.php b/src/Controllers/AuthorizeController.php index 96902af..b004f71 100644 --- a/src/Controllers/AuthorizeController.php +++ b/src/Controllers/AuthorizeController.php @@ -41,20 +41,18 @@ class AuthorizeController implements RequestHandlerInterface $response = $oauth->response(); if (!$server->validateAuthorizeRequest($request, $response)) { - $response->getResponseBody(); return new JsonResponse(json_decode($response->getResponseBody(), true)); } $is_authorized = Arr::get($params, 'is_authorized', 0); $server->handleAuthorizeRequest($request, $response, $is_authorized, $actor->id); if ($is_authorized) { - // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); return new JsonResponse([ 'code' => $code ]); } - $response->getResponseBody(); + return new JsonResponse(json_decode($response->getResponseBody(), true)); } } diff --git a/src/Middlewares/ResourceScopeMiddleware.php b/src/Middlewares/ResourceScopeMiddleware.php index 288acbd..620e1a5 100644 --- a/src/Middlewares/ResourceScopeMiddleware.php +++ b/src/Middlewares/ResourceScopeMiddleware.php @@ -4,10 +4,12 @@ namespace FoskyM\OAuthCenter\Middlewares; use Flarum\Foundation\ErrorHandling\ExceptionHandler\IlluminateValidationExceptionHandler; use Flarum\Foundation\ErrorHandling\JsonApiFormatter; +use Flarum\Settings\SettingsRepositoryInterface; use FoskyM\OAuthCenter\OAuth; use FoskyM\OAuthCenter\Storage; use Illuminate\Support\Arr; use Illuminate\Validation\ValidationException; +use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface; @@ -20,6 +22,11 @@ use Tobscure\JsonApi\Exception\Handler\ResponseBag; use FoskyM\OAuthCenter\Models\Scope; class ResourceScopeMiddleware implements MiddlewareInterface { + protected $settings; + public function __construct(SettingsRepositoryInterface $settings) + { + $this->settings = $settings; + } public function process(Request $request, RequestHandlerInterface $handler): Response { $path = $request->getUri()->getPath(); @@ -27,12 +34,11 @@ class ResourceScopeMiddleware implements MiddlewareInterface if ($token !== '' && $scope = Scope::get_path_scope($path)) { if (strtolower($request->getMethod()) === strtolower($scope->method)) { try { - $oauth = new OAuth(); + $oauth = new OAuth($this->settings); $server = $oauth->server(); $request = $oauth->request(); if (!$server->verifyResourceRequest($request::createFromGlobals(), null, $scope->scope)) { - $server->getResponse()->send('json'); - die; + return new JsonResponse(json_decode($server->getResponse()->getResponseBody(), true)); } /*$error = new ResponseBag('422', [ [ diff --git a/src/Middlewares/UnsetCsrfMiddleware.php b/src/Middlewares/UnsetCsrfMiddleware.php new file mode 100644 index 0000000..f1a2d72 --- /dev/null +++ b/src/Middlewares/UnsetCsrfMiddleware.php @@ -0,0 +1,35 @@ +getUri()->getPath(); + if (in_array($path, $uri)) { + $request = $request->withAttribute('bypassCsrfToken', true); + } + + return $handler->handle($request); + } +} From 940a989fb4f3f6f9e2d2f980ebeb6e3df243dfc8 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 03:38:45 +0800 Subject: [PATCH 29/35] feat: oauth token(TokenController.php) --- src/Controllers/TokenController.php | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Controllers/TokenController.php diff --git a/src/Controllers/TokenController.php b/src/Controllers/TokenController.php new file mode 100644 index 0000000..63be7ed --- /dev/null +++ b/src/Controllers/TokenController.php @@ -0,0 +1,40 @@ +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)); + } +} From 95e195a5dede5e0d22633f27afdc306cda23cd73 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 05:30:13 +0800 Subject: [PATCH 30/35] feat: oauth resource(ResourceScopeMiddleware.php) --- extend.php | 8 +++- src/Controllers/ApiUserController.php | 49 +++++++++++++++++++++ src/Middlewares/ResourceScopeMiddleware.php | 36 +++++++-------- src/OAuth.php | 6 ++- 4 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 src/Controllers/ApiUserController.php diff --git a/extend.php b/extend.php index c3ec7d9..b4680d5 100644 --- a/extend.php +++ b/extend.php @@ -12,6 +12,7 @@ namespace FoskyM\OAuthCenter; use Flarum\Extend; +use Flarum\Http\Middleware\AuthenticateWithHeader; use Flarum\Http\Middleware\CheckCsrfToken; use FoskyM\OAuthCenter\Middlewares\ResourceScopeMiddleware; use FoskyM\OAuthCenter\Middlewares\UnsetCsrfMiddleware; @@ -41,14 +42,17 @@ return [ ->get('/oauth-scopes', 'oauth.scopes.list', Api\Controller\ListScopeController::class) ->post('/oauth-scopes', 'oauth.scopes.create', Api\Controller\CreateScopeController::class) ->patch('/oauth-scopes/{id}', 'oauth.scopes.update', Api\Controller\UpdateScopeController::class) - ->delete('/oauth-scopes/{id}', 'oauth.scopes.delete', Api\Controller\DeleteScopeController::class), + ->delete('/oauth-scopes/{id}', 'oauth.scopes.delete', Api\Controller\DeleteScopeController::class) + + ->get('/user', 'user.show', Controllers\ApiUserController::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')) + ->insertAfter(AuthenticateWithHeader::class, ResourceScopeMiddleware::class), (new Extend\Middleware('forum')) ->insertBefore(CheckCsrfToken::class, UnsetCsrfMiddleware::class), - (new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class), ]; diff --git a/src/Controllers/ApiUserController.php b/src/Controllers/ApiUserController.php new file mode 100644 index 0000000..d20fdd2 --- /dev/null +++ b/src/Controllers/ApiUserController.php @@ -0,0 +1,49 @@ +settings = $settings; + } + + public function handle(ServerRequestInterface $request): ResponseInterface + { + $actor = RequestUtil::getActor($request); + $actor = $actor->toArray(); + $data = [ + 'id' => $actor['id'], + 'username' => $actor['username'], + 'nickname' => $actor['nickname'], + 'avatar_url' => $actor['avatar_url'], + 'email' => $actor['email'], + 'is_email_confirmed' => $actor['is_email_confirmed'], + 'joined_at' => $actor['joined_at'], + 'last_seen_at' => $actor['last_seen_at'], + 'discussion_count' => $actor['discussion_count'], + 'comment_count' => $actor['comment_count'], + ]; + return new JsonResponse($data); + } +} diff --git a/src/Middlewares/ResourceScopeMiddleware.php b/src/Middlewares/ResourceScopeMiddleware.php index 620e1a5..22a0216 100644 --- a/src/Middlewares/ResourceScopeMiddleware.php +++ b/src/Middlewares/ResourceScopeMiddleware.php @@ -5,6 +5,7 @@ namespace FoskyM\OAuthCenter\Middlewares; use Flarum\Foundation\ErrorHandling\ExceptionHandler\IlluminateValidationExceptionHandler; use Flarum\Foundation\ErrorHandling\JsonApiFormatter; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\User; use FoskyM\OAuthCenter\OAuth; use FoskyM\OAuthCenter\Storage; use Illuminate\Support\Arr; @@ -15,11 +16,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Flarum\Http\RequestUtil; -use Flarum\Api\JsonApiResponse; -use Tobscure\JsonApi\Document; -use Tobscure\JsonApi\Exception\Handler\ResponseBag; - use FoskyM\OAuthCenter\Models\Scope; + class ResourceScopeMiddleware implements MiddlewareInterface { protected $settings; @@ -29,31 +27,29 @@ class ResourceScopeMiddleware implements MiddlewareInterface } public function process(Request $request, RequestHandlerInterface $handler): Response { - $path = $request->getUri()->getPath(); + if (!$request->getAttribute('originalUri')) { + return $handler->handle($request); + } + + $path = $request->getAttribute('originalUri')->getPath(); $token = Arr::get($request->getQueryParams(), 'access_token', ''); if ($token !== '' && $scope = Scope::get_path_scope($path)) { if (strtolower($request->getMethod()) === strtolower($scope->method)) { try { $oauth = new OAuth($this->settings); $server = $oauth->server(); - $request = $oauth->request(); - if (!$server->verifyResourceRequest($request::createFromGlobals(), null, $scope->scope)) { + $oauth_request = $oauth->request()::createFromGlobals(); + + if (!$server->verifyResourceRequest($oauth_request, null, $scope->scope)) { return new JsonResponse(json_decode($server->getResponse()->getResponseBody(), true)); } - /*$error = new ResponseBag('422', [ - [ - 'status' => '422', - 'code' => 'validation_error', - 'source' => [ - 'pointer' => $path, - ], - 'detail' => 'Yikes! The access token don\'t has the scope.', - ], - ]); - $document = new Document(); - $document->setErrors($error->getErrors()); - return new JsonApiResponse($document, $error->getStatus());*/ + $token = $server->getAccessTokenData($oauth_request); + $actor = User::find($token['user_id']); + + $request = RequestUtil::withActor($request, $actor); + $request = $request->withAttribute('bypassCsrfToken', true); + $request = $request->withoutAttribute('session'); } catch (ValidationException $exception) { $handler = resolve(IlluminateValidationExceptionHandler::class); diff --git a/src/OAuth.php b/src/OAuth.php index 8718df0..66c67a8 100644 --- a/src/OAuth.php +++ b/src/OAuth.php @@ -36,9 +36,13 @@ class OAuth { return new Request; } + + public function storage(): Storage + { + return new Storage; + } public function server(): Server { - $storage = new Storage; $server = new Server($storage, array( 'allow_implicit' => $this->settings->get('foskym-oauth-center.allow_implicit') == "1", From faee03069cb5497a9b5c3c2de884eb3378683f6a Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 05:35:14 +0800 Subject: [PATCH 31/35] fix: scope's method --- js/dist/admin.js | Bin 10705 -> 10758 bytes js/dist/admin.js.map | Bin 32032 -> 32185 bytes js/src/admin/pages/ScopesPage.js | 2 ++ 3 files changed, 2 insertions(+) diff --git a/js/dist/admin.js b/js/dist/admin.js index 5ecd5a14bc40c5397206e56b141b0f8928da3af7..4431dad9559beeba7b65eae039647b2d7b21b787 100644 GIT binary patch delta 127 zcmcZ@+!nH70Vh|8ZHZoUoxFgHfAS8V_fXzl z-rtNNn{V=67dF)?N-fSWElN&}FGwuOuu{@bEXdSX(k{^}O3X{i&kZgq%FIjGFwxY> bO)bgDPq9*RcMVb6yg@0PjnR2BhvrED4h1X- delta 69 zcmZn*xfr}*0VkKUZHZo_+ZkI{uEvn|q`#uBs)50I_U&DI)>^y>9{&NdTTrB zBsw}K>Hww9oq?(yLxHl+A)6BwDj6BgH{Vuda+gt1P%la?&Mz%WPK_@}EXh!}Qc%}V oEXdSXSJ0kZ7$MALqB;3uq9nU|ZfZ$Je#+zpiSnE8W;lxg0MZ>R+W-In delta 49 zcmdn_n{mM}#tp4f?3M0eI{uDTn|q`#u(EnPIu|)_?oy~^WHjE)qQvAr*(Z{Bb91Jd F2msaN5d{DM diff --git a/js/src/admin/pages/ScopesPage.js b/js/src/admin/pages/ScopesPage.js index 2bf51c7..71b94fa 100644 --- a/js/src/admin/pages/ScopesPage.js +++ b/js/src/admin/pages/ScopesPage.js @@ -86,6 +86,8 @@ export default class ScopesPage extends Page { const scope = app.store.createRecord('oauth-scopes'); scope.save({ 'scope': 'Scope.' + this.randomString(8), + 'resource_path': '/api/' + this.randomString(4), + 'method': 'GET', }).then(this.scopes.push(scope)); }, }, app.translator.trans(this.translationPrefix + 'add_button')))), From b66e8a56d1cb497620a25816dc1434844aa21f09 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 05:40:04 +0800 Subject: [PATCH 32/35] chore: remove the authorized page temporarily --- js/dist/forum.js | Bin 7505 -> 7274 bytes js/dist/forum.js.map | Bin 24629 -> 24346 bytes js/src/forum/index.js | 27 +++++++++++++-------------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index f4ad0d6a20adbf77ed341c38341668ac4f6ee250..a7988c6e1d86349de08e03ddaed666efbedb0d46 100644 GIT binary patch delta 780 zcmbV~&ubGw6vvsZZIZ?$Md**%7Po=c88WQ#P>^gEjEX`L&7mL|L)oU&blc=jnVoHj zZIK=nkClhsJ$Um{bI_xIfQO1_y$Mo0dhEezY$#rPdCdFqoyYs|{aQS_vA>!HI{;fU z?MNy)u(`RJlc(VD>e=K3@NEH6ODKQ2DT*@%-VnMdt8nn)F3EwX9iWoAs}a<7Ai-8t zbHTQi(2+8khXrdCuUU79LTx=V@r$*U2MC0;Hr{zRX)$4s%oCE8fGKt zu&S^%KnZl;4E!PIko_1e69Q<*zF|2rm%1Oo#;r(e3Aq|SsiZ4@L*#01T|%hs4&F?R zqKpmUVJwNS<0B)>z56=sbYSajAU=if;q|~5{?J_=JC@^=+S2lPpN6APFXVX`Hi!v9YX4CV) zsW$@yaVc2Y**PuY+vJ$x@hQno{F$^3*`bTs9-@>mr57pR#9yg;2Ar@iH%0$1e4L&c zQeL&@D%?wlp7NAqpw)d%1IA^4RZnADt3gu>MQPs_|C<7@XTl3lDWmv#YQFnDvuBZZ zcj?m60IA@@*hf<7TI2iHm7Xm%lg?%ou2IP6yj)&aq4w`=g$LPEM(r9HT*is|Xwe*r_&03ZMW delta 915 zcmbVK&rcIU7|oO@Eu|EU0;QzcZep3S!&(xF+Byf~uY?#hp^1m4A=`G^E-W+4>@1{| z2LA-iBwjsuH<2EU@$SikhJ!c%01^)*UQL`XBAhwwmz}rod*8nI&GEhO#e-%_7!ETy zk`{*?3zW-c2d@;1*Zb*dfxDCin^f2}mlm@H+@i9`E8@f96JQD=Ee1I%H3L?c4rc~~ z5>wO_R0cwyh$=*GsN0c8fGHVysq5Fsc3u!hcZ?+=?2c~6j1)@j0WYz99*GL85?i$N zL?-@iVW^%( z6Y6brPQ8kbs~^#uibp5Z7yYDTSPjLd$2UUmb5uH2+8HQi%AC8>@yu!{_adb1oKe;_ z<<3Ys1lJK>RqtbWFJa>T$P}2^g$VT!UMv()I7%oxK9v_%-F0+OYffWtj|Hwvh_D3p zJ#Ch*$&N?=!|Gie>nOg(4ISr6JT=HAo}jvJC2U=f67{68{5tn&>7SB%JeIx6NTph0 z${q7Fj4(@^uiFwj2=lYqVGm*I&saw9cQ)yRjs8LMQv|%|FJC(z0%f&0`4N=+za|eN z+3>DO#4RuI+fd|9V&-KREwLh2=CLB814chT|+|yg#2c8IOZUBX4&fx7l;TAD}a!htQlGVC7)XHFt^X{WE?LTsV4nW~viSH?pO{#ZH(x*%*^ zI=3{ju+e$Qy%Yy(GH8mtU#*UnLz0xb@rKl$_gnQY4yspgT}|&!zGSA)oxJX+&2U_1`x*f=SX0+}O4aq5Sp((r{?^P9nJnOd=w zJe)f8t4BeZmahIU(<&N?LW#_f(a|K-NUF cfhLJV9Ywdb3J>W4P{HG<5^QoV=?tZ { }; extend(UserPage.prototype, 'navItems', function (items) { if (app.session.user && app.session.user.id() === this.user.id()) { - items.add( - 'authorized', - LinkButton.component( - { - href: app.route('user.authorized', { username: this.user.username() }), - icon: 'fas fa-user-friends', - }, - [ - app.translator.trans('foskym-oauth-center.forum.page.label.authorized'), - // this.user.moderatorNoteCount() > 0 ? {this.user.moderatorNoteCount()} : '', - ] - ), - -110 - ); + // items.add( + // 'authorized', + // LinkButton.component( + // { + // href: app.route('user.authorized', { username: this.user.username() }), + // icon: 'fas fa-user-friends', + // }, + // [ + // app.translator.trans('foskym-oauth-center.forum.page.label.authorized'), + // ] + // ), + // -110 + // ); } }); }); From a92398ca8dadcd60992706d10752c8237df9edfc Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 05:40:58 +0800 Subject: [PATCH 33/35] feat: support bearer authorization --- src/Middlewares/ResourceScopeMiddleware.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Middlewares/ResourceScopeMiddleware.php b/src/Middlewares/ResourceScopeMiddleware.php index 22a0216..951cbd4 100644 --- a/src/Middlewares/ResourceScopeMiddleware.php +++ b/src/Middlewares/ResourceScopeMiddleware.php @@ -9,6 +9,7 @@ use Flarum\User\User; use FoskyM\OAuthCenter\OAuth; use FoskyM\OAuthCenter\Storage; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; @@ -20,6 +21,7 @@ use FoskyM\OAuthCenter\Models\Scope; class ResourceScopeMiddleware implements MiddlewareInterface { + const TOKEN_PREFIX = 'Bearer '; protected $settings; public function __construct(SettingsRepositoryInterface $settings) { @@ -31,8 +33,17 @@ class ResourceScopeMiddleware implements MiddlewareInterface return $handler->handle($request); } + $headerLine = $request->getHeaderLine('authorization'); + + $parts = explode(';', $headerLine); + + if (isset($parts[0]) && Str::startsWith($parts[0], self::TOKEN_PREFIX)) { + $token = substr($parts[0], strlen(self::TOKEN_PREFIX)); + } else { + $token = Arr::get($request->getQueryParams(), 'access_token', ''); + } $path = $request->getAttribute('originalUri')->getPath(); - $token = Arr::get($request->getQueryParams(), 'access_token', ''); + if ($token !== '' && $scope = Scope::get_path_scope($path)) { if (strtolower($request->getMethod()) === strtolower($scope->method)) { try { From ca160ae8ebd7040f60c05cdebb0552de6514f897 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 05:57:49 +0800 Subject: [PATCH 34/35] feat: add default scope --- js/dist/admin.js | Bin 10758 -> 10967 bytes js/dist/admin.js.map | Bin 32185 -> 32671 bytes js/src/admin/pages/ScopesPage.js | 9 ++--- ...d_default_record_to_oauth_scopes_table.php | 32 ++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 migrations/2023_10_02_add_default_record_to_oauth_scopes_table.php diff --git a/js/dist/admin.js b/js/dist/admin.js index 4431dad9559beeba7b65eae039647b2d7b21b787..d45ab951e49994f9979fc42cdff021044c6ec29b 100644 GIT binary patch delta 359 zcmZn*xgNTKmqQ@lwnQ&aqfFB}IX|zsL?L~0Jcs&Z7Y;$j^vz)$pEwxfH+u@+V`q$? zd{$Cpa)4wFP~fa&JeyfcW^rOtPHKvkl73=ArhaL0YLSwyt!=7aQEG91X;E@&d_iJK zhK8n^no@3RNk)DONH%|Rzk=jsH$|bzVG34OBp8ud9G{Y!mROoo0yAd5EeYCD+ypZL zGPl}!DC@V{YY1yIyT*S; E05@}b`~Uy| delta 143 zcmcZ}+7_~bmqQ@kwnQ&aqfFB}IX|zsL?M21Jcs&Z7Y;$j_|0J)pEwxPH+u@+V`ogC zd{$Cpa)4wFP~fa&JlkX@MTyDP3O+!3-sJld(v#~H_$PBo%EA@uPoAgb4d$h74p7c! Y1~U~V-%&dcWt~xf4PkA*q4A#)0C}e}fdBvi diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map index 7406db647646b63ec2f40ef59b387c5b3e5836ef..21de8ca152871911b1fc02799a8a5e0dc4c8c62f 100644 GIT binary patch delta 1350 zcmbtS%}*0S6whL!9K;J)6liHnTNEZjfkJB}=FRN3EVZl(r5Y2Zv&~s!W zvB(UFv>x_!9vZTAHV;q{EC&$gQ*ovNqzqQ%0Aqq>04|qQc_ubg+;;c0NA1GgO?>YT z9v{`24)SAZfHG$S#FPl*uG@e9@2KVh)MA|Y)3k_Dl_fwd6jYq^xNycZ=Gv#@B+FQv zpxNR!-^Ut6U%7$hP-LYX@Lqw zfzlT0q(&@25#(-ie0HMy?y62VBRrQ2?q$#1VgoGLF;!zKmsOzF$D? z-mqr`)}7y`F1sI9BV3A#sS~_nPs*Aulk zyDD|eNT+(3I|V=%lNt?Hnl)u$i_1NqD=^Na=~6|p60mc~+YM=HezFX6pFcV{_Hf#}TQpk0wTLM`Fm zfF5-~YX?Ci{|c&<@oAt>iQt>StWtXt>>Bt-HS(bmq=%*8xN-}h2Yp^AB{6CDI3x9o zS<342C|MG)g`a}MN(DPYCzUD=hN4QXwG_I4j^~Sw>~hJ>pY=9!m8yBBZZ;~-dd|F2 z&2AP>o%T*oPkRSPven{9vtiZ;y`hkI-Mr--m(9&WC68Ygg7|s)Tl{~Zij5n2b0ym> zZ4zATYp$v2|AY674GB4qJvkR%OV>`H`m;~pZ$4YYE5{UkvDk&i>Pf_XF=R025kNW@s delta 1034 zcmbtSzfV(96wZr-A_`Fy8kAC7S`vGkQcC%eDDm9e`yTI=QlUI6ZcvRB=nt?3aWG-f z$?Z596LobW=|nVc?k2{?f53soK_>=1=M^H(Ea#rwd(QWL=R5b!A7k&p*nQS}df2)n za*%Ak=13!|SGy~coscXcFIMR;oANXsiDTKSB3De7 zPm>Uw%Ze5mvm#ebHoz8J67*e`kY2%;1NQ9}&H8bg)JbSC7QSjE(Fr@{7IgJEbn+z7 zhZ8)Kpqv?Ac9zzqm%L$;Xhf367N#QC0K7hrCi{ZdfJ%}DeLE&T9P zO{5P$l}mrhNvH~bjEo!A=I_YP4Segi<0tDZ{wV(9ylFmY7?k+%YwaTLZk)j{ZX34W e?{5BdhYZ{+ci^|>TUaYRZ@wx8F5~B?-~R$kStrK; diff --git a/js/src/admin/pages/ScopesPage.js b/js/src/admin/pages/ScopesPage.js index 71b94fa..2fb36d0 100644 --- a/js/src/admin/pages/ScopesPage.js +++ b/js/src/admin/pages/ScopesPage.js @@ -50,11 +50,13 @@ export default class ScopesPage extends Page { 'PATCH': 'PATCH', }, value: scope[key]() || 'GET', + disabled: scope.resource_path() === '/api/user' && key === 'method', onchange: (value) => { this.saveScopeInfo(index, key, value); }, }) : key === 'is_default' ? Checkbox.component({ state: scope[key]() === 1 || false, + disabled: scope.resource_path() === '/api/user' && key === 'is_default', onchange: (checked) => { this.scopes[index].is_default((this.scopes[index].is_default() + 1) % 2) this.saveScopeInfo(index, key, checked ? 1 : 0); @@ -62,21 +64,20 @@ export default class ScopesPage extends Page { }) : m('input.FormControl', { type: 'text', value: scope[key]() || '', + disabled: scope.resource_path() === '/api/user' && key === 'resource_path', onchange: (event) => { - this.saveScopeInfo(index, key, event.target.value); }, })) ), - m('td', Button.component({ + (scope.resource_path() !== '/api/user' && m('td', Button.component({ className: 'Button Button--icon', icon: 'fas fa-times', onclick: () => { this.scopes[index].delete(); this.scopes.splice(index, 1); - }, - })), + }))), ])), m('tr', m('td', { colspan: 7, diff --git a/migrations/2023_10_02_add_default_record_to_oauth_scopes_table.php b/migrations/2023_10_02_add_default_record_to_oauth_scopes_table.php new file mode 100644 index 0000000..bda0bc2 --- /dev/null +++ b/migrations/2023_10_02_add_default_record_to_oauth_scopes_table.php @@ -0,0 +1,32 @@ + function (Builder $schema) { + if (!$schema->hasTable('oauth_scopes')) { + return; + } + $schema->getConnection()->table('oauth_scopes')->insert([ + 'scope' => 'user.read', + 'resource_path' => '/api/user', + 'method' => 'GET', + 'is_default' => 1, + 'scope_name' => '获取用户信息', + 'scope_icon' => 'fas fa-user', + 'scope_desc' => '访问该用户({user})的个人信息等', + ]); + }, + 'down' => function (Builder $schema) { + + }, +]; From 58d2ed6494aa533d03e380ae4798957ad2de5428 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Mon, 2 Oct 2023 06:04:31 +0800 Subject: [PATCH 35/35] fix: scope --- js/dist/forum.js | Bin 7274 -> 7326 bytes js/dist/forum.js.map | Bin 24346 -> 24677 bytes .../forum/components/oauth/AuthorizePage.js | 6 ++++++ 3 files changed, 6 insertions(+) diff --git a/js/dist/forum.js b/js/dist/forum.js index a7988c6e1d86349de08e03ddaed666efbedb0d46..4c8eaf1927b88490d10604e458d1307a9d9dd51e 100644 GIT binary patch delta 65 zcmaE5G0$?tK0cGO#3F@M+akTpyp+@m|1^yfz2fBjf>aGnP3u%UT|@h#=+s!-600J; V;+)LnRE<;}LrtB{`}o%I0ss#_7MuV8 delta 12 UcmbPd`O0F$KEBPL_}1_O04U!D;s5{u diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index d4916cf5bc7143332d795ca46bdbf467389fe3f3..c314cbb2fb74d137def3cca5fd099869976ea448 100644 GIT binary patch delta 1860 zcmah}OHUhD6xK*p5{Me}u)%gxFpv@uw-B3`2@i4S&cqmF95BRj+AIh-cnH{LY=gsw z?kZKPROzUjKE$?CHkH^`RVsDYY`U&gbyMXB^bho$b3G(vQ!hMo&+Gfncg~$}e=+`f zW&Cv3+TyIbrpU;>)$<=)10S63h@_NB#}c-bYfJQ>Ulwcl9#wQmOOcgoUtvH($}F1H zBOR4s!yYBtt{La(d{U$_hl^#s1adBt=Tflu?4eZp@|91erl7 zsVX{K1E!FvOua`7^K$4`=)v-8`hJoLEAC_*3clM$6~6R^)tE`-tX)NgrN~KTPnr~k z2efQW@gYC$*>X}A;wHBs%9d0!Y6jl;dW-|O(iSmlaHnnXbix#yQf>;zM8ApUP$bDL zJPGGQeU`jhOV!}jC&8Ei^ z*nH7K(RhL*)TH|^3Y>O^PEROIZhKL?rc6ZbOJUwly%kAP#iYlkj*bT!Giu?S?45dZ zo?FsR9x!6A!EDwMhOVbT80naggx!n7z{^TAE}8-xcGaP+V{pkg$6?ApcF#jXqFc4* z4p7FfP1iWV*?dhlQAOGs1jX!ZF#%`(VEBbLvZ?t>_`Bu_{Ne8#I8<7o=Q#4`YF!@= zu&F&uZ@h{@AQ1B%>D*)eaN%L#ZkM;rQ%c$mQ|~c`e;=6i!V#S0ufgAeF(VFbU7?kI zl0;cmi@5S-PEjLj356i`ECkZS9aKjwrLsAr&ZFdvw4#jVDAc=p4F|sI8Z{>2x2|Y7 zX7hpzYG8%yrK!$x(E?w0w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6}cjREuf2s?)}>EQHW8GEPPdGEF309ihTUN{^`dM)fKn!Fk_7{S-! ztw7h%wUhX1@8W&Kb!8oX55M(pH%~+)>$M|l{_=p}WV66O5(Go&fy7%z4rEHdEbK>a z&$PTvvH+h(Ze1I(E|m;?ABnFHdEmS!7H3JDEq>ak49~S1aT)UcX zahF_vLgDI}Qf=#Ag9`HAHIlJ;n3_51!vVS)m3-(9DqcySi@p1dC RF~G%f_fcbV`R)Cu);}i4&gB3A diff --git a/js/src/forum/components/oauth/AuthorizePage.js b/js/src/forum/components/oauth/AuthorizePage.js index a3ac9d9..6d31f91 100644 --- a/js/src/forum/components/oauth/AuthorizePage.js +++ b/js/src/forum/components/oauth/AuthorizePage.js @@ -69,6 +69,12 @@ export default class AuthorizePage extends IndexPage { let default_scopes = []; this.scopes.map(scope => { + let index = scopes_temp.indexOf(scope.scope()); + if (index > -1) { + scopes_temp[index] = scope; + } else { + scopes_temp.slice(index, 1); + } if (scope.is_default() === 1) { default_scopes.push(scope); }