I am trying to use OAuth authentication. When my callback is called, and success is indicated there are no result parameters. This is the code:
// implement the OAuth callback method
function onOAuthMessage(message as Authentication.OAuthMessage) as Void {
System.println(message.responseCode);
if (message.data != null) {
// Extract the access code from the JSON response. (should this be URL instead?)
$.code = message.data[$.OAUTH_CODE];
$.error = message.data[$.OAUTH_ERROR];
System.println("oauth success");
System.println(message.data);
System.println(message);
System.println("code="+code);
System.println("error="+error);
Storage.setValue("OAstate",2); // success
}
else {
// return an error
System.println("oauth error");
Storage.setValue("OAstate",3);
}
}
// the OAuth service can now be used with a makeWebRequest() call
}
In the simulator, the callback is called twice. Fail the first time, and success the 2nd time. I see on the debug console:
-1001
oauth error
400
oauth success
{}
Obj: 146
code=null
error=null
In both the simulator and the real device, I don't get any authorization code.
In the simulator the response code in the success case is 400.
On a real device, it seems to be called just once, and go to the fail case and the response code is 202.
In both the simulator and the real device, I don't get any authorization code. On the real watch, after accepting the authorization, the message "Something went wrong, try again" message is flashed momentarily in the Connect IQ app.
The service that I am using appends the authorization code to the result URI like this:
https://your_redirect.com?code=ABC
The example for the onOAuthMessage() function seems to imply that the result parameters are returned in JSON. So may be that is why I get no code.
But if so, then this conflicts with the makeOAuthRequest() call, resultType parameter which can only be set to
Authentication.OAUTH_RESULT_TYPE_URL
Which is correct?
I'm lost as to what is going on and how to debug. The HTTP traffic window is empty during this interchange.