User does not stay connected (authenticated) to the system (Backend) when changing scene (APP with Composer & API RESTFUL)

Greetings.

I am developing an app to display content using the Joomla 3 CMS as backend (latest version). Its contents are private, that is, the user must authenticate (login) to access them. I have properly configured a commercial Restful API in the CMS for the following actions: Login, Logout and Bring content.

The API works well if I access it from any RESTFUL client (and in the Corona simulator), that is, it responds appropriately to requests.

In the app I am using composer and I manage the following logic (in general):

  1. I display a form with username / password to authenticate the user (Scene Login)

  2. If the authentication is successful I call another scene to display contents (Contents), which are brought to the APP using the RESTFUL API in the Joomla CMS.

So far everything looks normal in the simulator, authentication, recovery and content deployment

I generate the build for android without problems or error messages and I install it on the device (read several devices with different versions of android)

When running the app on the android devices and if the authentication is successful, when it arrives to bring the contents the API responds that it is not authenticated. It is as if the change of scene in the device “erased” the connection (which does not happen in the simulator).

How different it is to run composer in the simulator to run it on the device. Should we have something extra in mind?

Thanks in advance for your answers,

SolCa

Corona Build: 3161

It’s likely a difference in how Android handles connections more than a composer issue. There really isn’t enough data here to see how you’re authenticating, if your service is using some token/session information that’s not being preserved/sent on the second request.

I would suggest making a minimal app that calls your connection, fetch data sequence without any underlying scene/input code, dump all returned event tables to see what all data you’re getting back. Once you have that process in place then you can adapt it back to your full app.

Rob

Rob, thanks for your response.

The Restful API uses the native Joomla CMS authentication. Here is some information about it to complement the information in this post: 

https://docs.joomla.org/J3.x:Creating_an_Authentication_Plugin_for_Joomla

However, I will do what you suggest and I will be placing the result in this forum.

Regards and thanks again,

SolCa

Hi again.

I have built a completely independent script with integrated LOGIN, GET CONTENT and LOGOUT processes.

The situation is the same as I reported earlier. In the simulator everything works fine but not in the devices. Authentication is lost.

THE RESULTS

Results in Simulator Copyright (C) 2009-2017 C o r o n a L a b s I n c . Version: 3.0.0 Build: 2017.3163 Loading project from: ~/Documents/Corona Projects/Joomla API Project sandbox folder: ~/Library/Application Support/Corona Simulator/Joomla API-9A727CDABC6782D70E95CC27F73448CA Platform: Sensation / x86\_64 / 10.12.3 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.22.29 / 2017.3163 / es-CO | CO | es\_CO | es Wed Nov 1 14:22:05 2017 =\> Authenticating Wed Nov 1 14:22:06 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} Wed Nov 1 14:22:06 2017 =\> Authenticated :) Wed Nov 1 14:22:06 2017 =\> Bringing Categories Wed Nov 1 14:22:06 2017 =\> RESPONSE DEPLOY CATS: {"status":"ok","total":6,"categories":[{"id":"10","title":"Cat APP 01","description":"\<p\>Contenidos categor\u00eda 01 para la APP\<\/p\>","parent\_id":"9","numitems":null},{"id":"11","title":"Cat APP 02","description":"\<p\>Contenidos Categor\u00eda APP 02\<\/p\>","parent\_id":"9","numitems":null},{"id":"12","title":"Cat APP 03","description":"\<p\>Contenidos Categor\u00eda APP 03\<\/p\>","parent\_id":"9","numitems":null},{"id":"13","title":"Cat APP 04","description":"\<p\>Contenidos Categor\u00eda APP 04\<\/p\>","parent\_id":"9","numitems":null},{"id":"14","title":"Cat APP 05","description":"\<p\>Contenidos Categor\u00eda APP 05\<\/p\>","parent\_id":"9","numitems":null},{"id":"15","title":"Cat APP 06","description":"\<p\>Contenidos Categor\u00eda APP 06\<\/p\>","parent\_id":"9","numitems":null}]} Wed Nov 1 14:22:06 2017 =\> Deploying Cats END Wed Nov 1 14:22:07 2017 =\> RESPONSE LOGOUT: {"status":"ok"} Wed Nov 1 14:22:07 2017 =\> Logout OK :)

On Android Device 1 BUILD SUCCESSFUL Total time: 0 seconds Excluding specified files from build: excluding: LaunchScreen.storyboardc excluding: Icon.png excluding: Icon-\*dpi.png excluding: Images.xcassets BuildID: 59fa1f794a6f5 BUILD SUCCESSFUL Total time: 7 seconds Android build succeeded in 52 seconds adb I 7281 253141 usb\_osx.cpp:259] Found vid=22b8 pid=2e76 serial=TA0930IJ75 adb I 7281 253141 usb\_osx.cpp:259] Installing and running Joomla API on MotoE2(4G-LTE) 4763 KB/s (7416706 bytes in 1.520s) pkg: /data/local/tmp/CoronaSDK566e1d5c2783fa125ab9c2916106f72d.apk Success Starting: Intent { cmp=com.phonemas.Joomla\_API/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- MotoE2(4G-LTE): Platform: MotoE2(4G-LTE) / ARM Neon / 6.0 / Adreno (TM) 306 / OpenGL ES 3.0 V@140.0 AU@ (GIT@I14a17c7611) / 2017.3163 / español | US | es\_US | es MotoE2(4G-LTE): Wed Nov 1 14:25:59 2017 =\> Authenticating MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> Authenticated :) MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> Bringing Categories MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> NO deploying cats :( ---------- Device Log Finished ----------

Note: Module not found = User no rights access

LOGIN=OK

On android device 2 Installing and running Joomla API on GT-I9300 4516 KB/s (7416706 bytes in 1.603s) pkg: /data/local/tmp/CoronaSDK566e1d5c2783fa125ab9c2916106f72d.apk Success Starting: Intent { cmp=com.phonemas.Joomla\_API/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- GT-I9300: mDVFSHelper.acquire() GT-I9300: mDVFSHelper.release() GT-I9300: Platform: GT-I9300 / ARM Neon / 4.3 / Mali-400 MP / OpenGL ES 2.0 / 2017.3163 / español | US | es\_US | es GT-I9300: Wed Nov 1 14:29:22 2017 =\> Authenticating GT-I9300: Wed Nov 1 14:29:24 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} GT-I9300: Wed Nov 1 14:29:24 2017 =\> Authenticated :) GT-I9300: Wed Nov 1 14:29:24 2017 =\> Bringing Categories GT-I9300: Wed Nov 1 14:29:24 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} GT-I9300: Wed Nov 1 14:29:24 2017 =\> NO deploying cats :(

THE CODE

[lua] local json = require( "json" ) local nuevoLogin = "phonemas" local nuevoPassWord = "\*\*\*\*\*\*\*" local AP="https://a\*\*\*\*\*\*.com/api/v1" local API\_KEY="\*\*\*\*\*\*" local cateRootId="9" local maxCates="20" -- LOGIN Process local function handleLogin( event ) if (event.isError) then print ("=\> Network Error", event.response) else print (os.date().." =\> RESPONSE LOGIN:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Authenticated :)") -- GET CONTENT START -- GET CONTENT PROCESSS local function handleCats( event ) if (event.isError) then print ("=\> Network Error", event.response) else print (os.date().." =\> RESPONSE DEPLOY CATS:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Deploying Cats END") -- LOGOUT PROCESS START -- LOGOUT PROCESS local function handleLogout( event ) if (event.isError) then print ("=\> Network Error in LOGOUT", event.response) else print (os.date().." =\> RESPONSE LOGOUT:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Logout OK :)") else print (os.date().." =\> Logout NO OK :(") end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY -- print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/get/user/logout" network.request( urlAP, "POST", handleLogout,params) --network.request( urlAP, "POST", handleLogout,params) -- LOGOUT PROCESS END else print (os.date().." =\> NO deploying cats :(") end end end print (os.date().." =\> Bringing Categories") local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY.."&rootid="..cateRootId --print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/get/content/categories" --network.request( urlAP, "POST", handleCats,params ) network.request( urlAP, "POST", handleCats,params ) -- GET CONTENT END else print (os.date().."=\> NO Authenticated :(") end end end print (os.date().." =\> Authenticating") local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY.."&username="..nuevoLogin.."&password="..nuevoPassWord --print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/post/user/login" --network.request( urlAP, "POST", handleLogin,params ) network.request( urlAP, "POST", handleLogin,params ) [/lua]

Can you:

print( json.prettify( event ) )

on your various event responses?

Rob

Done add print( json.prettify( event ) ) in event responses

Android Device Output

---------- Device Log Starts ---------- GT-I9300: mDVFSHelper.acquire() GT-I9300: mDVFSHelper.release() GT-I9300: Platform: GT-I9300 / ARM Neon / 4.3 / Mali-400 MP / OpenGL ES 2.0 / 2017.3163 / español | US | es\_US | es GT-I9300: Wed Nov 1 17:21:40 2017 =\> Authenticating GT-I9300: Wed Nov 1 17:21:41 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} GT-I9300: { GT-I9300: "bytesEstimated":52, GT-I9300: "bytesTransferred":52, GT-I9300: "name":"networkRequest", GT-I9300: "phase":"ended", GT-I9300: "requestId":"\<type 'userdata' is not supported by JSON.\>", GT-I9300: "response":"{\"status\":\"ok\",\"userid\":\"611\",\"username\":\"phonemas\"}", GT-I9300: "responseHeaders":{ GT-I9300: "Connection":"Keep-Alive", GT-I9300: "Content-Length":"52", GT-I9300: "Date":"Wed, 01 Nov 2017 22:21:41 GMT", GT-I9300: "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=5017nct735j6offfn0eims98d3; path=/; secure; HttpOnly,f3c23b987a2a06f5da5f9d601a36ff96=mj75q43hmajssv0ihsc00i0eh1; path=/; secure; HttpOnly,f3c23b987a2a06f5da5f9d601a36ff96=mj75q43hmajssv0ihsc00i0eh1; path=/; secure; HttpOnly,joomla\_user\_state=logged\_in; path=/; secure; httponly", GT-I9300: "Content-Disposition":"attachment;filename=\"response.json\"", GT-I9300: "X-Android-Received-Millis":"1509574901625", GT-I9300: "X-Android-Sent-Millis":"1509574900848", GT-I9300: "Keep-Alive":"timeout=5, max=100", GT-I9300: "X-Powered-By":"PHP/5.6.25RC1", GT-I9300: "Content-Type":"application/json", GT-I9300: "HTTP-STATUS-LINE":"HTTP/1.1 200 OK", GT-I9300: "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" GT-I9300: }, GT-I9300: "responseType":"text", GT-I9300: "status":200, GT-I9300: "url":"https://XXXXXXX.com/api/v1/post/user/login", GT-I9300: "isError":false GT-I9300: } GT-I9300: Wed Nov 1 17:21:41 2017 =\> Authenticated :) GT-I9300: Wed Nov 1 17:21:41 2017 =\> Bringing Categories GT-I9300: Wed Nov 1 17:21:41 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} GT-I9300: { GT-I9300: "bytesEstimated":77, GT-I9300: "bytesTransferred":77, GT-I9300: "name":"networkRequest", GT-I9300: "phase":"ended", GT-I9300: "requestId":"\<type 'userdata' is not supported by JSON.\>", GT-I9300: "response":"{\"status\":\"ko\",\"error\_code\":\"REQ\_MNF\",\"error\_description\":\"Module not found\"}", GT-I9300: "responseHeaders":{ GT-I9300: "Connection":"Keep-Alive", GT-I9300: "Content-Length":"77", GT-I9300: "Date":"Wed, 01 Nov 2017 22:21:42 GMT", GT-I9300: "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=rjcr8lr97qv73vtr2bk1kmak52; path=/; secure; HttpOnly", GT-I9300: "Content-Disposition":"attachment;filename=\"response.json\"", GT-I9300: "X-Android-Received-Millis":"1509574901955", GT-I9300: "X-Android-Sent-Millis":"1509574901650", GT-I9300: "Keep-Alive":"timeout=5, max=99", GT-I9300: "X-Powered-By":"PHP/5.6.25RC1", GT-I9300: "Content-Type":"application/json", GT-I9300: "HTTP-STATUS-LINE":"HTTP/1.1 200 OK", GT-I9300: "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" GT-I9300: }, GT-I9300: "responseType":"text", GT-I9300: "status":200, GT-I9300: "url":"https:/XXXXXXX.com/api/v1/get/content/categories", GT-I9300: "isError":false GT-I9300: } GT-I9300: Wed Nov 1 17:21:41 2017 =\> NO deploying cats :(

Simulator Output

Copyright (C) 2009-2017 C o r o n a L a b s I n c . Version: 3.0.0 Build: 2017.3163 Loading project from: ~/Documents/Corona Projects/Joomla API Project sandbox folder: ~/Library/Application Support/Corona Simulator/Joomla API-9A727CDABC6782D70E95CC27F73448CA Platform: Sensation / x86\_64 / 10.12.3 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.22.29 / 2017.3163 / es-CO | CO | es\_CO | es Wed Nov 1 17:17:23 2017 =\> Authenticating Wed Nov 1 17:17:24 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} { "bytesEstimated":52, "bytesTransferred":52, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\",\"userid\":\"611\",\"username\":\"phonemas\"}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Date":"Wed, 01 Nov 2017 22:17:23 GMT", "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=uoifj6lb6k9pnef34tkfg108v0; path=/; secure; HttpOnly, 20d682d3bb9da03673d621808384e810=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/, f3c23b987a2a06f5da5f9d601a36ff96=s0l16tcrr8q9dl9h1v73glugh2; path=/; secure; HttpOnly, f3c23b987a2a06f5da5f9d601a36ff96=s0l16tcrr8q9dl9h1v73glugh2; path=/; secure; HttpOnly, joomla\_user\_state=logged\_in; path=/; secure; httponly", "Content-Disposition":"attachment;filename=\"response.json\"", "Keep-Alive":"timeout=5, max=100", "X-Powered-By":"PHP/5.6.25RC1", "Content-Length":"52", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://appcc.phonemas.com/api/v1/post/user/login", "isError":false } Wed Nov 1 17:17:24 2017 =\> Authenticated :) Wed Nov 1 17:17:24 2017 =\> Bringing Categories Wed Nov 1 17:17:24 2017 =\> RESPONSE DEPLOY CATS: {"status":"ok","total":6,"categories":[{"id":"10","title":"Cat APP 01","description":"\<p\>Contenidos categor\u00eda 01 para la APP\<\/p\>","parent\_id":"9","numitems":null},{"id":"11","title":"Cat APP 02","description":"\<p\>Contenidos Categor\u00eda APP 02\<\/p\>","parent\_id":"9","numitems":null},{"id":"12","title":"Cat APP 03","description":"\<p\>Contenidos Categor\u00eda APP 03\<\/p\>","parent\_id":"9","numitems":null},{"id":"13","title":"Cat APP 04","description":"\<p\>Contenidos Categor\u00eda APP 04\<\/p\>","parent\_id":"9","numitems":null},{"id":"14","title":"Cat APP 05","description":"\<p\>Contenidos Categor\u00eda APP 05\<\/p\>","parent\_id":"9","numitems":null},{"id":"15","title":"Cat APP 06","description":"\<p\>Contenidos Categor\u00eda APP 06\<\/p\>","parent\_id":"9","numitems":null}]} { "bytesEstimated":780, "bytesTransferred":780, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\",\"total\":6,\"categories\":[{\"id\":\"10\",\"title\":\"Cat APP 01\",\"description\":\"\<p\>Contenidos categor\\u00eda 01 para la APP\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"11\",\"title\":\"Cat APP 02\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 02\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"12\",\"title\":\"Cat APP 03\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 03\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"13\",\"title\":\"Cat APP 04\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 04\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"14\",\"title\":\"Cat APP 05\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 05\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"15\",\"title\":\"Cat APP 06\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 06\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null}]}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Content-Length":"780", "Keep-Alive":"timeout=5, max=99", "X-Powered-By":"PHP/5.6.25RC1", "Date":"Wed, 01 Nov 2017 22:17:24 GMT", "Content-Disposition":"attachment;filename=\"response.json\"", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://XXXXXX.com/api/v1/get/content/categories", "isError":false } Wed Nov 1 17:17:24 2017 =\> Deploying Cats END Wed Nov 1 17:17:25 2017 =\> RESPONSE LOGOUT: {"status":"ok"} { "bytesEstimated":15, "bytesTransferred":15, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\"}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Date":"Wed, 01 Nov 2017 22:17:24 GMT", "Set-Cookie":"20d682d3bb9da03673d621808384e810=1; expires=Thu, 02-Nov-2017 22:17:25 GMT; Max-Age=86400; path=/; secure; httponly, f3c23b987a2a06f5da5f9d601a36ff96=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0, joomla\_user\_state=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/", "Content-Disposition":"attachment;filename=\"response.json\"", "Keep-Alive":"timeout=5, max=98", "X-Powered-By":"PHP/5.6.25RC1", "Content-Length":"15", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://XXXXXX.com/api/v1/get/user/logout", "isError":false } Wed Nov 1 17:17:25 2017 =\> Logout OK :)

Solved:

It is necessary to recover a session_id (variable) in the login process and then, include it in the other requests.

The  session_id must be exported in the response of the server in the login process.

I hope this solution helps someone.

Regards,

Solón

It’s likely a difference in how Android handles connections more than a composer issue. There really isn’t enough data here to see how you’re authenticating, if your service is using some token/session information that’s not being preserved/sent on the second request.

I would suggest making a minimal app that calls your connection, fetch data sequence without any underlying scene/input code, dump all returned event tables to see what all data you’re getting back. Once you have that process in place then you can adapt it back to your full app.

Rob

Rob, thanks for your response.

The Restful API uses the native Joomla CMS authentication. Here is some information about it to complement the information in this post: 

https://docs.joomla.org/J3.x:Creating_an_Authentication_Plugin_for_Joomla

However, I will do what you suggest and I will be placing the result in this forum.

Regards and thanks again,

SolCa

Hi again.

I have built a completely independent script with integrated LOGIN, GET CONTENT and LOGOUT processes.

The situation is the same as I reported earlier. In the simulator everything works fine but not in the devices. Authentication is lost.

THE RESULTS

Results in Simulator Copyright (C) 2009-2017 C o r o n a L a b s I n c . Version: 3.0.0 Build: 2017.3163 Loading project from: ~/Documents/Corona Projects/Joomla API Project sandbox folder: ~/Library/Application Support/Corona Simulator/Joomla API-9A727CDABC6782D70E95CC27F73448CA Platform: Sensation / x86\_64 / 10.12.3 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.22.29 / 2017.3163 / es-CO | CO | es\_CO | es Wed Nov 1 14:22:05 2017 =\> Authenticating Wed Nov 1 14:22:06 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} Wed Nov 1 14:22:06 2017 =\> Authenticated :) Wed Nov 1 14:22:06 2017 =\> Bringing Categories Wed Nov 1 14:22:06 2017 =\> RESPONSE DEPLOY CATS: {"status":"ok","total":6,"categories":[{"id":"10","title":"Cat APP 01","description":"\<p\>Contenidos categor\u00eda 01 para la APP\<\/p\>","parent\_id":"9","numitems":null},{"id":"11","title":"Cat APP 02","description":"\<p\>Contenidos Categor\u00eda APP 02\<\/p\>","parent\_id":"9","numitems":null},{"id":"12","title":"Cat APP 03","description":"\<p\>Contenidos Categor\u00eda APP 03\<\/p\>","parent\_id":"9","numitems":null},{"id":"13","title":"Cat APP 04","description":"\<p\>Contenidos Categor\u00eda APP 04\<\/p\>","parent\_id":"9","numitems":null},{"id":"14","title":"Cat APP 05","description":"\<p\>Contenidos Categor\u00eda APP 05\<\/p\>","parent\_id":"9","numitems":null},{"id":"15","title":"Cat APP 06","description":"\<p\>Contenidos Categor\u00eda APP 06\<\/p\>","parent\_id":"9","numitems":null}]} Wed Nov 1 14:22:06 2017 =\> Deploying Cats END Wed Nov 1 14:22:07 2017 =\> RESPONSE LOGOUT: {"status":"ok"} Wed Nov 1 14:22:07 2017 =\> Logout OK :)

On Android Device 1 BUILD SUCCESSFUL Total time: 0 seconds Excluding specified files from build: excluding: LaunchScreen.storyboardc excluding: Icon.png excluding: Icon-\*dpi.png excluding: Images.xcassets BuildID: 59fa1f794a6f5 BUILD SUCCESSFUL Total time: 7 seconds Android build succeeded in 52 seconds adb I 7281 253141 usb\_osx.cpp:259] Found vid=22b8 pid=2e76 serial=TA0930IJ75 adb I 7281 253141 usb\_osx.cpp:259] Installing and running Joomla API on MotoE2(4G-LTE) 4763 KB/s (7416706 bytes in 1.520s) pkg: /data/local/tmp/CoronaSDK566e1d5c2783fa125ab9c2916106f72d.apk Success Starting: Intent { cmp=com.phonemas.Joomla\_API/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- MotoE2(4G-LTE): Platform: MotoE2(4G-LTE) / ARM Neon / 6.0 / Adreno (TM) 306 / OpenGL ES 3.0 V@140.0 AU@ (GIT@I14a17c7611) / 2017.3163 / español | US | es\_US | es MotoE2(4G-LTE): Wed Nov 1 14:25:59 2017 =\> Authenticating MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> Authenticated :) MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> Bringing Categories MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} MotoE2(4G-LTE): Wed Nov 1 14:26:01 2017 =\> NO deploying cats :( ---------- Device Log Finished ----------

Note: Module not found = User no rights access

LOGIN=OK

On android device 2 Installing and running Joomla API on GT-I9300 4516 KB/s (7416706 bytes in 1.603s) pkg: /data/local/tmp/CoronaSDK566e1d5c2783fa125ab9c2916106f72d.apk Success Starting: Intent { cmp=com.phonemas.Joomla\_API/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- GT-I9300: mDVFSHelper.acquire() GT-I9300: mDVFSHelper.release() GT-I9300: Platform: GT-I9300 / ARM Neon / 4.3 / Mali-400 MP / OpenGL ES 2.0 / 2017.3163 / español | US | es\_US | es GT-I9300: Wed Nov 1 14:29:22 2017 =\> Authenticating GT-I9300: Wed Nov 1 14:29:24 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} GT-I9300: Wed Nov 1 14:29:24 2017 =\> Authenticated :) GT-I9300: Wed Nov 1 14:29:24 2017 =\> Bringing Categories GT-I9300: Wed Nov 1 14:29:24 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} GT-I9300: Wed Nov 1 14:29:24 2017 =\> NO deploying cats :(

THE CODE

[lua] local json = require( "json" ) local nuevoLogin = "phonemas" local nuevoPassWord = "\*\*\*\*\*\*\*" local AP="https://a\*\*\*\*\*\*.com/api/v1" local API\_KEY="\*\*\*\*\*\*" local cateRootId="9" local maxCates="20" -- LOGIN Process local function handleLogin( event ) if (event.isError) then print ("=\> Network Error", event.response) else print (os.date().." =\> RESPONSE LOGIN:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Authenticated :)") -- GET CONTENT START -- GET CONTENT PROCESSS local function handleCats( event ) if (event.isError) then print ("=\> Network Error", event.response) else print (os.date().." =\> RESPONSE DEPLOY CATS:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Deploying Cats END") -- LOGOUT PROCESS START -- LOGOUT PROCESS local function handleLogout( event ) if (event.isError) then print ("=\> Network Error in LOGOUT", event.response) else print (os.date().." =\> RESPONSE LOGOUT:",event.response) local response = json.decode( event.response ) if (response.status =="ok") then print (os.date().." =\> Logout OK :)") else print (os.date().." =\> Logout NO OK :(") end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY -- print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/get/user/logout" network.request( urlAP, "POST", handleLogout,params) --network.request( urlAP, "POST", handleLogout,params) -- LOGOUT PROCESS END else print (os.date().." =\> NO deploying cats :(") end end end print (os.date().." =\> Bringing Categories") local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY.."&rootid="..cateRootId --print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/get/content/categories" --network.request( urlAP, "POST", handleCats,params ) network.request( urlAP, "POST", handleCats,params ) -- GET CONTENT END else print (os.date().."=\> NO Authenticated :(") end end end print (os.date().." =\> Authenticating") local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "api\_key="..API\_KEY.."&username="..nuevoLogin.."&password="..nuevoPassWord --print ("BORRAR ESTO: "..body) local params = {} params.headers = headers params.body = body local urlAP = AP.."/post/user/login" --network.request( urlAP, "POST", handleLogin,params ) network.request( urlAP, "POST", handleLogin,params ) [/lua]

Can you:

print( json.prettify( event ) )

on your various event responses?

Rob

Done add print( json.prettify( event ) ) in event responses

Android Device Output

---------- Device Log Starts ---------- GT-I9300: mDVFSHelper.acquire() GT-I9300: mDVFSHelper.release() GT-I9300: Platform: GT-I9300 / ARM Neon / 4.3 / Mali-400 MP / OpenGL ES 2.0 / 2017.3163 / español | US | es\_US | es GT-I9300: Wed Nov 1 17:21:40 2017 =\> Authenticating GT-I9300: Wed Nov 1 17:21:41 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} GT-I9300: { GT-I9300: "bytesEstimated":52, GT-I9300: "bytesTransferred":52, GT-I9300: "name":"networkRequest", GT-I9300: "phase":"ended", GT-I9300: "requestId":"\<type 'userdata' is not supported by JSON.\>", GT-I9300: "response":"{\"status\":\"ok\",\"userid\":\"611\",\"username\":\"phonemas\"}", GT-I9300: "responseHeaders":{ GT-I9300: "Connection":"Keep-Alive", GT-I9300: "Content-Length":"52", GT-I9300: "Date":"Wed, 01 Nov 2017 22:21:41 GMT", GT-I9300: "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=5017nct735j6offfn0eims98d3; path=/; secure; HttpOnly,f3c23b987a2a06f5da5f9d601a36ff96=mj75q43hmajssv0ihsc00i0eh1; path=/; secure; HttpOnly,f3c23b987a2a06f5da5f9d601a36ff96=mj75q43hmajssv0ihsc00i0eh1; path=/; secure; HttpOnly,joomla\_user\_state=logged\_in; path=/; secure; httponly", GT-I9300: "Content-Disposition":"attachment;filename=\"response.json\"", GT-I9300: "X-Android-Received-Millis":"1509574901625", GT-I9300: "X-Android-Sent-Millis":"1509574900848", GT-I9300: "Keep-Alive":"timeout=5, max=100", GT-I9300: "X-Powered-By":"PHP/5.6.25RC1", GT-I9300: "Content-Type":"application/json", GT-I9300: "HTTP-STATUS-LINE":"HTTP/1.1 200 OK", GT-I9300: "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" GT-I9300: }, GT-I9300: "responseType":"text", GT-I9300: "status":200, GT-I9300: "url":"https://XXXXXXX.com/api/v1/post/user/login", GT-I9300: "isError":false GT-I9300: } GT-I9300: Wed Nov 1 17:21:41 2017 =\> Authenticated :) GT-I9300: Wed Nov 1 17:21:41 2017 =\> Bringing Categories GT-I9300: Wed Nov 1 17:21:41 2017 =\> RESPONSE DEPLOY CATS: {"status":"ko","error\_code":"REQ\_MNF","error\_description":"Module not found"} GT-I9300: { GT-I9300: "bytesEstimated":77, GT-I9300: "bytesTransferred":77, GT-I9300: "name":"networkRequest", GT-I9300: "phase":"ended", GT-I9300: "requestId":"\<type 'userdata' is not supported by JSON.\>", GT-I9300: "response":"{\"status\":\"ko\",\"error\_code\":\"REQ\_MNF\",\"error\_description\":\"Module not found\"}", GT-I9300: "responseHeaders":{ GT-I9300: "Connection":"Keep-Alive", GT-I9300: "Content-Length":"77", GT-I9300: "Date":"Wed, 01 Nov 2017 22:21:42 GMT", GT-I9300: "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=rjcr8lr97qv73vtr2bk1kmak52; path=/; secure; HttpOnly", GT-I9300: "Content-Disposition":"attachment;filename=\"response.json\"", GT-I9300: "X-Android-Received-Millis":"1509574901955", GT-I9300: "X-Android-Sent-Millis":"1509574901650", GT-I9300: "Keep-Alive":"timeout=5, max=99", GT-I9300: "X-Powered-By":"PHP/5.6.25RC1", GT-I9300: "Content-Type":"application/json", GT-I9300: "HTTP-STATUS-LINE":"HTTP/1.1 200 OK", GT-I9300: "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" GT-I9300: }, GT-I9300: "responseType":"text", GT-I9300: "status":200, GT-I9300: "url":"https:/XXXXXXX.com/api/v1/get/content/categories", GT-I9300: "isError":false GT-I9300: } GT-I9300: Wed Nov 1 17:21:41 2017 =\> NO deploying cats :(

Simulator Output

Copyright (C) 2009-2017 C o r o n a L a b s I n c . Version: 3.0.0 Build: 2017.3163 Loading project from: ~/Documents/Corona Projects/Joomla API Project sandbox folder: ~/Library/Application Support/Corona Simulator/Joomla API-9A727CDABC6782D70E95CC27F73448CA Platform: Sensation / x86\_64 / 10.12.3 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-10.22.29 / 2017.3163 / es-CO | CO | es\_CO | es Wed Nov 1 17:17:23 2017 =\> Authenticating Wed Nov 1 17:17:24 2017 =\> RESPONSE LOGIN: {"status":"ok","userid":"611","username":"phonemas"} { "bytesEstimated":52, "bytesTransferred":52, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\",\"userid\":\"611\",\"username\":\"phonemas\"}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Date":"Wed, 01 Nov 2017 22:17:23 GMT", "Set-Cookie":"f3c23b987a2a06f5da5f9d601a36ff96=uoifj6lb6k9pnef34tkfg108v0; path=/; secure; HttpOnly, 20d682d3bb9da03673d621808384e810=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/, f3c23b987a2a06f5da5f9d601a36ff96=s0l16tcrr8q9dl9h1v73glugh2; path=/; secure; HttpOnly, f3c23b987a2a06f5da5f9d601a36ff96=s0l16tcrr8q9dl9h1v73glugh2; path=/; secure; HttpOnly, joomla\_user\_state=logged\_in; path=/; secure; httponly", "Content-Disposition":"attachment;filename=\"response.json\"", "Keep-Alive":"timeout=5, max=100", "X-Powered-By":"PHP/5.6.25RC1", "Content-Length":"52", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://appcc.phonemas.com/api/v1/post/user/login", "isError":false } Wed Nov 1 17:17:24 2017 =\> Authenticated :) Wed Nov 1 17:17:24 2017 =\> Bringing Categories Wed Nov 1 17:17:24 2017 =\> RESPONSE DEPLOY CATS: {"status":"ok","total":6,"categories":[{"id":"10","title":"Cat APP 01","description":"\<p\>Contenidos categor\u00eda 01 para la APP\<\/p\>","parent\_id":"9","numitems":null},{"id":"11","title":"Cat APP 02","description":"\<p\>Contenidos Categor\u00eda APP 02\<\/p\>","parent\_id":"9","numitems":null},{"id":"12","title":"Cat APP 03","description":"\<p\>Contenidos Categor\u00eda APP 03\<\/p\>","parent\_id":"9","numitems":null},{"id":"13","title":"Cat APP 04","description":"\<p\>Contenidos Categor\u00eda APP 04\<\/p\>","parent\_id":"9","numitems":null},{"id":"14","title":"Cat APP 05","description":"\<p\>Contenidos Categor\u00eda APP 05\<\/p\>","parent\_id":"9","numitems":null},{"id":"15","title":"Cat APP 06","description":"\<p\>Contenidos Categor\u00eda APP 06\<\/p\>","parent\_id":"9","numitems":null}]} { "bytesEstimated":780, "bytesTransferred":780, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\",\"total\":6,\"categories\":[{\"id\":\"10\",\"title\":\"Cat APP 01\",\"description\":\"\<p\>Contenidos categor\\u00eda 01 para la APP\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"11\",\"title\":\"Cat APP 02\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 02\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"12\",\"title\":\"Cat APP 03\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 03\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"13\",\"title\":\"Cat APP 04\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 04\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"14\",\"title\":\"Cat APP 05\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 05\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null},{\"id\":\"15\",\"title\":\"Cat APP 06\",\"description\":\"\<p\>Contenidos Categor\\u00eda APP 06\<\\/p\>\",\"parent\_id\":\"9\",\"numitems\":null}]}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Content-Length":"780", "Keep-Alive":"timeout=5, max=99", "X-Powered-By":"PHP/5.6.25RC1", "Date":"Wed, 01 Nov 2017 22:17:24 GMT", "Content-Disposition":"attachment;filename=\"response.json\"", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://XXXXXX.com/api/v1/get/content/categories", "isError":false } Wed Nov 1 17:17:24 2017 =\> Deploying Cats END Wed Nov 1 17:17:25 2017 =\> RESPONSE LOGOUT: {"status":"ok"} { "bytesEstimated":15, "bytesTransferred":15, "name":"networkRequest", "phase":"ended", "requestId":"\<type 'userdata' is not supported by JSON.\>", "response":"{\"status\":\"ok\"}", "responseHeaders":{ "Connection":"Keep-Alive", "Content-Type":"application/json", "Date":"Wed, 01 Nov 2017 22:17:24 GMT", "Set-Cookie":"20d682d3bb9da03673d621808384e810=1; expires=Thu, 02-Nov-2017 22:17:25 GMT; Max-Age=86400; path=/; secure; httponly, f3c23b987a2a06f5da5f9d601a36ff96=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0, joomla\_user\_state=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/", "Content-Disposition":"attachment;filename=\"response.json\"", "Keep-Alive":"timeout=5, max=98", "X-Powered-By":"PHP/5.6.25RC1", "Content-Length":"15", "Server":"Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod\_fcgid/2.3.9 PHP/5.6.25RC1" }, "responseType":"text", "status":200, "url":"https://XXXXXX.com/api/v1/get/user/logout", "isError":false } Wed Nov 1 17:17:25 2017 =\> Logout OK :)

Solved:

It is necessary to recover a session_id (variable) in the login process and then, include it in the other requests.

The  session_id must be exported in the response of the server in the login process.

I hope this solution helps someone.

Regards,

Solón