Use new syndication target model when processing MicroPub requests

This commit is contained in:
Jonny Barnes 2022-10-23 20:38:12 +01:00
parent 976929e9b9
commit 66257e7e9b
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
6 changed files with 61 additions and 52 deletions

View file

@ -12,6 +12,7 @@ use App\Services\Micropub\HEntryService;
use App\Services\Micropub\UpdateService;
use App\Services\TokenService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Lcobucci\JWT\Encoding\CannotDecodeContent;
use Lcobucci\JWT\Token\InvalidTokenStructure;
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
@ -44,13 +45,14 @@ class MicropubController extends Controller
* This function receives an API request, verifies the authenticity
* then passes over the info to the relevant Service class.
*
* @param Request $request
* @return JsonResponse
*/
public function post(): JsonResponse
public function post(Request $request): JsonResponse
{
try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token'));
} catch (RequiredConstraintsViolated | InvalidTokenStructure | CannotDecodeContent $exception) {
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
} catch (RequiredConstraintsViolated | InvalidTokenStructure | CannotDecodeContent) {
$micropubResponses = new MicropubResponses();
return $micropubResponses->invalidTokenResponse();
@ -62,15 +64,15 @@ class MicropubController extends Controller
return $micropubResponses->tokenHasNoScopeResponse();
}
$this->logMicropubRequest(request()->all());
$this->logMicropubRequest($request->all());
if ((request()->input('h') == 'entry') || (request()->input('type.0') == 'h-entry')) {
if (stristr($tokenData->claims()->get('scope'), 'create') === false) {
if (($request->input('h') === 'entry') || ($request->input('type.0') === 'h-entry')) {
if (stripos($tokenData->claims()->get('scope'), 'create') === false) {
$micropubResponses = new MicropubResponses();
return $micropubResponses->insufficientScopeResponse();
}
$location = $this->hentryService->process(request()->all(), $this->getCLientId());
$location = $this->hentryService->process($request->all(), $this->getCLientId());
return response()->json([
'response' => 'created',
@ -78,13 +80,13 @@ class MicropubController extends Controller
], 201)->header('Location', $location);
}
if (request()->input('h') == 'card' || request()->input('type.0') == 'h-card') {
if (stristr($tokenData->claims()->get('scope'), 'create') === false) {
if ($request->input('h') === 'card' || $request->input('type.0') === 'h-card') {
if (stripos($tokenData->claims()->get('scope'), 'create') === false) {
$micropubResponses = new MicropubResponses();
return $micropubResponses->insufficientScopeResponse();
}
$location = $this->hcardService->process(request()->all());
$location = $this->hcardService->process($request->all());
return response()->json([
'response' => 'created',
@ -92,14 +94,14 @@ class MicropubController extends Controller
], 201)->header('Location', $location);
}
if (request()->input('action') == 'update') {
if (stristr($tokenData->claims()->get('scope'), 'update') === false) {
if ($request->input('action') === 'update') {
if (stripos($tokenData->claims()->get('scope'), 'update') === false) {
$micropubResponses = new MicropubResponses();
return $micropubResponses->insufficientScopeResponse();
}
return $this->updateService->process(request()->all());
return $this->updateService->process($request->all());
}
return response()->json([