Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
24 Views

intel.security.secureTransport problem

Jump to solution

Hi, I was trying to use intel.security.secureTransport in my hybrid app. It works OK if i emulate it in Intel XDK itself but when i debug in App Preview or as .apk file on the phone. It returns with a "error code is: 9, error message is: Invalid instance ID provided" in the setHeader and sendRequest method below. Is there a bug?

function startSMSVerificationCode(mobileNumber){
    var transportInstanceID = 0;
    intel.security.secureTransport.open(
        function(instanceID) {
            transportInstanceID = instanceID;
            console.log("tiid: "+ transportInstanceID);
        },
        function(error) {console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},
        {url:"https://xxxxx", serverKey:publickey, method:"POST"}
    );
    intel.security.secureTransport.setHeaders(
        console.log("Setting Headers"),
        function(error) {
            console.log("htiid: "+ transportInstanceID);
            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},
        {instanceID: transportInstanceID, 'headers':{"Content-type": "application/x-www-form-urlencoded"}}
    );    
    intel.security.secureTransport.sendRequest(
        function(response){
            intel.security.secureData.createFromData(
                function (As1instanceID) {
                    intel.security.secureStorage.write(true,true,{'id':'As1', 'instanceID':As1instanceID })},
                function(error){console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},  
                {'data':response.responseBody}
            );
        },
        function(error) {
            console.log("Rtiid: "+ transportInstanceID);
            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},
        {instanceID: transportInstanceID, requestBody: "phone_number="+mobileNumber}
    );  
}

 

 

 

Tags (2)
0 Kudos

Accepted Solutions
Highlighted
Employee
24 Views

Hi Gary,

 

The API are asynchronous, that means that the result of the API is in the success callback.

For example, when you call intel.security.secureTransport.open you get instanceID, you should use it in the success callback and not outside of this scope.

 

Here is a modification that follows the asynchrony programming (please note that I haven’t tested it):

function startSMSVerificationCode(mobileNumber){
    var transportInstanceID = 0;
    intel.security.secureTransport.open(
        function(instanceID) {
            transportInstanceID = instanceID;
            console.log("tiid: "+ transportInstanceID);                                 
            intel.security.secureTransport.setHeaders(
                function (){
                    console.log("Setting Headers")                                                                                               
                    intel.security.secureTransport.sendRequest(
                        function(response){
                            intel.security.secureData.createFromData(
                                function (As1instanceID) {
                                    intel.security.secureStorage.write(true,true,{'id':'As1', 'instanceID':As1instanceID })},
                                function(error){console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},  
                                {'data':response.responseBody}
                            );
                        },
                        function(error) {
                            console.log("Rtiid: "+ transportInstanceID);
                            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},
                        {instanceID: transportInstanceID, requestBody: "phone_number="+mobileNumber}
                    );                                          
                },
                function(error) {
                    console.log("htiid: "+ transportInstanceID);
                    console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
                },
                {instanceID: transportInstanceID, 'headers':{"Content-type": "application/x-www-form-urlencoded"}}
            );                                                
        },
        function(error) {
            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
        },
        {url:"https://xxxxx", serverKey:publickey, method:"POST"}
    );          
}


You can use the code snippets as a baseline for your application https://software.intel.com/en-us/node/604512.

 

Thanks,

Ohad

 

View solution in original post

0 Kudos
6 Replies
Highlighted
Employee
24 Views

Emulator has limitations:

You should think of the Emulate tab as a Cordova API simulator, not as a device emulator. It provides you with a convenient viewport to help you visualize the approximate layout of your app on various devices and it simulatesthe core Cordova APIs to make it easier to debug apps that use those APIs. It does not simulate real devices nor does it simulate third-party Cordova plugin APIs. Getting your app to work in the Emulate tab is not a guarantee that it will work on a real device. Conversely, if things work on a real device but do not work in the Emulate tab, that is not an indication that your app is "broken." The only way to know with certainty that your app works as intended is to build it and install it on real devices.

Please build to run on actual device and test the behaviour.

One of our sample uses similar kind of API which you can refer to:

https://software.intel.com/en-us/xdk/article/my-private-photos-sample#app-security-api

0 Kudos
Highlighted
24 Views

Gary -- we're not experts at that API, so I rounded up several of the threads on this forum that have referenced the API and will ask the API expert to check your post. Please check these threads to see if there is anything useful for you:

 

0 Kudos
Highlighted
Beginner
24 Views

Hi Amrita, Paul,

Thanks for the reply. Ironically, as i stated above. it works in the 'emulate' tab but does not work in actual device (both using the debug tab and building the .apk and installing on the device)

Have i used the intel.security api the wrong way? Is there anything wrong in the way i code it?

- Gary

0 Kudos
Highlighted
24 Views

Hi Gary -- as I noted, neither of us is an expert with that API, so we've asked the real experts to respond to your post. Please also see the links I provided, which received help from those same experts, there might be some hints in there.

0 Kudos
Highlighted
Employee
25 Views

Hi Gary,

 

The API are asynchronous, that means that the result of the API is in the success callback.

For example, when you call intel.security.secureTransport.open you get instanceID, you should use it in the success callback and not outside of this scope.

 

Here is a modification that follows the asynchrony programming (please note that I haven’t tested it):

function startSMSVerificationCode(mobileNumber){
    var transportInstanceID = 0;
    intel.security.secureTransport.open(
        function(instanceID) {
            transportInstanceID = instanceID;
            console.log("tiid: "+ transportInstanceID);                                 
            intel.security.secureTransport.setHeaders(
                function (){
                    console.log("Setting Headers")                                                                                               
                    intel.security.secureTransport.sendRequest(
                        function(response){
                            intel.security.secureData.createFromData(
                                function (As1instanceID) {
                                    intel.security.secureStorage.write(true,true,{'id':'As1', 'instanceID':As1instanceID })},
                                function(error){console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},  
                                {'data':response.responseBody}
                            );
                        },
                        function(error) {
                            console.log("Rtiid: "+ transportInstanceID);
                            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);},
                        {instanceID: transportInstanceID, requestBody: "phone_number="+mobileNumber}
                    );                                          
                },
                function(error) {
                    console.log("htiid: "+ transportInstanceID);
                    console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
                },
                {instanceID: transportInstanceID, 'headers':{"Content-type": "application/x-www-form-urlencoded"}}
            );                                                
        },
        function(error) {
            console.log("Fail, error code is: " + error.code + ", error message is: " + error.message);
        },
        {url:"https://xxxxx", serverKey:publickey, method:"POST"}
    );          
}


You can use the code snippets as a baseline for your application https://software.intel.com/en-us/node/604512.

 

Thanks,

Ohad

 

View solution in original post

0 Kudos
Highlighted
Beginner
24 Views

Hi Ohad, Amrita, Paul

Thanks all, yes. I got it resolved :)

0 Kudos