From 71d7baf04fe987787817d80fb606e669691cb274 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 7 Sep 2016 14:32:42 +0530 Subject: [PATCH] Fixing iOS enrollement check polling url --- .../emm-web-agent/app/conf/config.json | 2 +- .../modules/enrollments/ios/agent-check.jag | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/conf/config.json b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/conf/config.json index b3f8ba7187..2400b07308 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/conf/config.json +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/conf/config.json @@ -5,7 +5,7 @@ "httpURL" : "%http.ip%", "enrollmentDir": "/emm-web-agent/enrollment", "iOSConfigRoot" : "%https.ip%/ios-enrollment/", - "iOSAPIRoot" : "%https.ip%/ios/", + "iOSAPIRoot" : "%https.ip%/api/device-mgt/ios/v1.0/", "dynamicClientRegistrationEndPoint" : "%https.ip%/dynamic-client-web/register/", "adminService":"%https.ip%", "idPServer":"%https.ip%", diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/ios/agent-check.jag b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/ios/agent-check.jag index 2283505a0b..797fc44b41 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/ios/agent-check.jag +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/ios/agent-check.jag @@ -22,6 +22,9 @@ var log = new Log("/modules/enrollments/ios/agent-check.jag"); var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var UAParser = require("/app/modules/ua-parser.min.js")["UAParser"]; +var tokenUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; +var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; + var parser = new UAParser(); var userAgent = request.getHeader("User-Agent"); parser.setUA(userAgent); @@ -39,25 +42,25 @@ if (platform != "iOS") { response["status"] = 200; response["content"] = {"deviceID" : null}; } else { - var deviceCheckURL = mdmProps["iOSAPIRoot"] + "device/deviceid"; - - var xhr = new XMLHttpRequest(); - xhr.open("POST", deviceCheckURL); + var deviceCheckURL = mdmProps["iOSAPIRoot"] + "devices/udid"; var challengeToken = session.get("iOSChallengeToken"); - var inputs = {"challengeToken" : challengeToken}; - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.setRequestHeader("Accept", "application/json"); - xhr.send(stringify(inputs)); + var payload = {"challengeToken" : challengeToken}; - if (xhr.status == 200) { - var responseObject = parse(xhr["responseText"]); - response["status"] = 200; - response["content"] = responseObject; - } else { - // server only returns 400 in case of bad request - response["status"] = 200; - response["content"] = {"deviceID" : null}; - } + serviceInvokers.XMLHttp.post( + deviceCheckURL, + stringify(payload), + function (restAPIResponse) { + var status = restAPIResponse["status"]; + if (status == 200) { + var responseContent = parse(restAPIResponse.responseText); + response["status"] = 200; + response["content"] = responseContent; + } else { + response["status"] = 200; + response["content"] = {"deviceID" : null}; + } + } + ); } } %> \ No newline at end of file