Comments (3)
Upon further investigation, it appears this is broken from Joomla 3.8 onwards.
In my custom plugin, I have the following basic structure:- /plugins/api/customapi/custom.php:-
class plgAPICustomApi extends ApiPlugin
{
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());
//load helper file
require_once JPATH_SITE.'/plugins/api/customapi/playlists/helper/simpleschema.php';
ApiResource::addIncludePath(dirname(__FILE__).'/customapi');
// Set resources & access
$this->setResourceAccess('custom', 'public', 'get');
}
}
/plugins/api/customapi/custom.php:-
class CustomApiApiResourceCustom extends ApiResource
{
/**
* get Method to get custom object
*
* @return JSON Object
*
* @since 1.0
*/
public function get()
{
$this->plugin->setResponse($this->getCustomObject());
}
public function getCustomObject()
{
// my code to get article data and process 3rd party apps.
}
}
My getCustomObject() function gets some data from the current viewed article. I am calling the custom API from an AJAX request.
I have since discovered that if I create an API key and hardcode this as an Authentication: Bearer header in the AJAX request, that I remain logged in. However, this is of no use - I literally do not care about authentication, whether the user is logged in or not, hence setResourceAccess is set to public.
What is the best way forward? Some, not all, of my "users" will be logged in, but I need the api to return the same data irrespective if they are logged in or not - so do not need nor wish to have to create an API token on the fly for each "user".
from com_api.
If you are sure that you will be using the API calls on the same Joomal site where the user is logged in, then you can set the X-Auth
header to session
.
However, usually if it is the same site, you can just create a controller.json.php instead of creating an API plugin.
from com_api.
Closing this, please reopen in case you continue to face issues even with the approach suggested above.
from com_api.
Related Issues (20)
- Add new authentication method using JFBConnect
- Change the charset of tables
- how to use JWT
- JSON as input? HOT 2
- input in JSON format not working
- API Rate Limit Exceeded,403,,,,[object Object] HOT 1
- FetchError: invalid json response body - GatsbyJS
- Not fetching user in log HOT 2
- com_api incorrectly returns 403 API Rate Limit Exceeded when rate limit has not yet been reached
- Add support for Secret Key HOT 2
- Joomla 4 support HOT 8
- API Key on POST requests - no effect? HOT 4
- API PUT method
- Joomla 4 Error HOT 1
- Warnings in PHP 8
- websiteurl/?option=com_api&app=articles&resource=article&format=json HOT 7
- Cannot hide or remove API User
- Moving toward Joomla >4 HOT 1
- Allow User Impersonation HOT 2
- Errors when installing plugins HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from com_api.