Magento – How to use magento rest api for native mobile app’s web service

magento-1.9web services

THIS IS NOT THE DUPLICATED POST OF What API does the Magento Mobile Store native app use?

Now i want to develop mobile app for this website. So for webservice i have created a custom module. In this module i have a controller called mobileApi. In this mobileApiController i am writing all webservice function. For an example getAllProducts().

Now, on the other hand i want to use magento rest api for access token and
Access token secret. If the access to rest api is valid then only my custom controller i.e. mobileApiController will return data.

I want the system to work like this,
At the time of App launch mobile app will call a webservice to authenticate the rest api access, and the webservice will return valid access token and
Access token secret.
After that on every webservice call it will first validate the rest api access, If access is valid then serve then serve the data otherwise shows authentication error.

I have developed everything and all is working fine, but the problem is at the time of App Launch, when i call the service to get access token and access token secret, magento system takes me to a page where it asks for authentication.

Screenshot (step 1)
enter image description here
After Login it shows me this page.

Screenshot (step 2)
enter image description here
Then if i authenticate the access then rest api get authenticated and returns access token and access token secret then webservice start serving the data.

But how do I manage this authentication from app? I need to skip these two step (step1 and step2).

I want to call the webservice to get the access token and access token secret at the app launch and right away get the access token and access token secret without these step 1 i.e. login and step 2 authorization.

Thanks in advance.

And my question is different than What API does the Magento Mobile Store native app use?.
I have search a lot about this but didn't find any similar.
So, don't give me any stack overflow/stack exchange link. No body asked this question earlier.

Best Answer

If you want to skip this authentication steps then you can use cUrl to submit those authentication form without clicking on button.

You can use following tutorial for cUrl: http://php.net/manual/en/book.curl.php

My point of view you need to implement these steps in such way that only once you need to create authentication token after that you can reuse it.

You can use rest.js to implment rest api calls from your mobile app. Refer below urls 1. https://github.com/cujojs/rest 2. https://spring.io/guides/gs/consuming-rest-restjs/

Thanks