First Context:
I am making a JS application that needs to call an api.
The application is a form full of multiple choice select elements. Depending on the selected elements data is sent to the api. The api should return an article's full text.
I have the following code which works. (no logic being done yet but I can do that later)
<?php
include ("/components/com_content/models/article.php");
class WdtoptionsApiResourceOptions extends ApiResource
{
public function post()
{
$data = new \stdClass;
$data = json_decode(file_get_contents("php://input"));
$result = new \stdClass;
$result->name = "WDTOptions Test";
$result->id = 6;
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_content/models' );
$article = JModelLegacy::getInstance( 'article', 'ContentModel');
$body = $article->getItem(6);
$result->optionlist = $body->introtext . $body->fulltext;
$result->postData = $data;
$this->plugin->setResponse( $result );
}
}
?>
The issue is that the article's text is returned by the api regardless of whether the user is logged into my site. This means that third parties could run their own apps off my api. They could also probe my api to work out how to use it. As my business depends on selling licences to this app I want to avoid that.
It has occurred to me that I could solve the problem by having my api output a hyperlink to the article and then having my front end call the article separately by a separate AJAX call. However this seems clunky and generally poor practice.
Is there way to have the ACL from the site apply to the API itself? I don't really want to use the JWT authentication process unless I have to.
Just to clarify I'm not expecting full code answers. Psudocode or overview is fine.