fix: get client info
This commit is contained in:
parent
35d9f280fb
commit
7a82b15c49
6 changed files with 64 additions and 9 deletions
|
@ -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),
|
||||
];
|
||||
|
|
BIN
js/dist/forum.js
generated
vendored
BIN
js/dist/forum.js
generated
vendored
Binary file not shown.
BIN
js/dist/forum.js.map
generated
vendored
BIN
js/dist/forum.js.map
generated
vendored
Binary file not shown.
|
@ -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 (
|
||||
<div className="AuthorizePage">
|
||||
<div className="container">
|
||||
|
|
|
@ -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 = '<PROTECT>';
|
||||
}
|
||||
$client = Client::where('client_id', $client_id)->get();
|
||||
|
||||
return $client;
|
||||
|
||||
|
|
35
src/Api/Serializer/ClientPublicSerializer.php
Normal file
35
src/Api/Serializer/ClientPublicSerializer.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace FoskyM\OAuthCenter\Api\Serializer;
|
||||
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
use FoskyM\OAuthCenter\Models\Client;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ClientPublicSerializer extends AbstractSerializer
|
||||
{
|
||||
protected $type = 'oauth-clients';
|
||||
|
||||
protected function getDefaultAttributes($model)
|
||||
{
|
||||
if (!($model instanceof Client)) {
|
||||
throw new InvalidArgumentException(
|
||||
get_class($this) . ' can only serialize instances of ' . Client::class
|
||||
);
|
||||
}
|
||||
|
||||
// See https://docs.flarum.org/extend/api.html#serializers for more information.
|
||||
|
||||
return [
|
||||
"id" => $model->id,
|
||||
"client_id" => $model->client_id,
|
||||
"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
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue