I have installed the com_api component and plugin from the official site for REST calls. I should authenticate user login with a web service at another domain using REST POST. How should I do it? I have the login form and how should I make POST request after submitting the form. There is no proper documentation and no tutorials even. Please help.
-
2Welcome tot JSE Rex. TechJoomla.com has a Documentation page, Forum and Support Ticket system. Have you tried using them first?– LodderMar 24, 2016 at 9:40
1 Answer
In the context of a REST Api, each call is stateless. So, there is no "user login".
In a Joomla site, when a user is authenticated, the browser receives a cookie to authorize the navigation and access to restricted areas.
Thus, in a REST Api, you have to implement an authorization protocol, like OAuth, to generate access tokens.
In TechJoomla's com_api, you call the authentication request with user and password (there's also an option for a global key), check ApiAuthenticationLogin and ApiAuthentication.
$app = JFactory::getApplication(); $key = $app->input->get('key','','STRING'); if(empty($key)) { $key = $app->input->post->get('key','','STRING'); } if(empty($key)) { $this->set('auth_method',$params->get('auth_method','username')); $this->set('auth_method',$params->get('auth_method','password')); $this->set('auth_method', $params->get('auth_method', 'login')); } else { $this->set('auth_method', $params->get('auth_method', 'key')); }
In the upcoming Joomla 3.6, a new Joomla official REST API will be included and it's currently being developed, more info here Preparing for webservices API in 3.6.
Github repo: Joomla Webservices
In this case, authentication is temporarily based on Redcore_Oauth2.
- About Webservices in redCORE:
Webservices in redCORE provide a RESTfull (Representational state transfer) interface for your site using HAL as a easy way to hyperlink between resources. Generating mapping XML file which will expose your webservice is very easy and you can read about them in following chapters.
We highly recommend using OAuth2 Server together with webservice API since it already brings token manipulation and ease of access to the data. redCORE already provide OAuth2 Server functionality and you can read more information here.
- Finally, I am the leading developer of JoomGap SDK for Joomla mobile apps. You can find a technical description of how it works an OAuth protocol implementation here, JoomGap Secure Channel - Technical Description and this is a specific example of how it works Composer App - How to enable the mobile App access.