question

bda2206@gmail.com avatar image
bda2206@gmail.com asked

Angular / ionic cannot authenticate after logging in

I've attempted to rewrite the javascript SDK into an ionic service.

the  main change is the execute request function

 

ExecuteRequest: function (completeUrl, data, authkey, authValue, callback) {
                 
if (callback != null && typeof (callback) != "function")
throw "Callback must be null of a function";
if (data == null)
data = {};

var startTime = new Date();
//var requestBody = JSON.stringify(data);
var requestBody = data;

var requestheaders = {
'Content-Type': 'application/x-www-form-urlencoded',
//; charset=UTF-8',
//'Content-Type': 'application/json',
'X-PlayFabSDK': 'JavaScriptSDK-' + PlayFab._internalSettings.sdkVersion
}
if (authkey != null)
requestheaders[authkey] = authValue;
console.log("executerequest headers" + JSON.stringify(requestheaders));
$http.post( completeUrl,
requestBody,
requestheaders )
.success(function(result){
// result.CallBackTimeMS = new Date() - startTime;
callback(result, null);

 

so I can login ok

04-22 00:15:31.919: I/chromium(950): [INFO:CONSOLE(54)] "result [{"code":200,"status":"OK","data":{"SessionTicket":"2CF133EE2E9F7CD1---65D6-8D369EF9089CB85-52C1A4A3F6FEDF73.AF12251C63647E82","PlayFabId":"2CF133EE2E9F7CD1","NewlyCreated":false,"SettingsForUser":{"NeedsAttribution":false},"LastLoginTime":"2016-04-21T13:59:34.916Z"}}]", source: file:///android_asset/www/scripts/login/login.service.js (54)

but trying to use the sesssion ticket doesnt work for me

 

04-22 00:15:32.389: I/chromium(950): [INFO:CONSOLE(63)] "executerequest headers{"Content-Type":"application/x-www-form-urlencoded","X-PlayFabSDK":"JavaScriptSDK-0.13.160328","X-Authentication":"2CF133EE2E9F7CD1---65D6-8D369EF9089CB85-52C1A4A3F6FEDF73.AF12251C63647E82"}", source: file:///android_asset/www/scripts/playfab/playfab.service.js (63)

04-22 00:15:32.679: I/chromium(950): [INFO:CONSOLE(64)] "androidpushregisterCallback err{"code":401,"status":"Unauthorized","error":"NotAuthenticated","errorCode":1074,"errorMessage":"Missing or invalid X-Authentication HTTP header"}", source: file:///android_asset/www/scripts/realpush/realpush.service.js (64)

04-22 00:15:32.679: I/chromium(950): [INFO:CONSOLE(64)] "androidpushregisterCallback err{"code":503,"status":"Service Unavailable","error":"Connection error","errorCode":2,"errorMessage":{"data":{"code":401,"status":"Unauthorized","error":"NotAuthenticated","errorCode":1074,"errorMessage":"Missing or invalid X-Authentication HTTP header"},"status":401,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"Content-Type":"application/x-www-form-urlencoded","X-PlayFabSDK":"JavaScriptSDK-0.13.160328","X-Authentication":"2CF133EE2E9F7CD1---65D6-8D369EF9089CB85-52C1A4A3F6FEDF73.AF12251C63647E82","url":"https://65D6.playfabapi.com/Client/AndroidDevicePushNotificationRegistration","data":{"DeviceToken":"APA91bFXbk2NfyFd2KNYYKIph72H8PszM_dHCvJx4YnnZJuQqG1ttELtFecBoZ5ItJ6SeAWQg-OyzyR3fr6M5KmE5uO6ZD1ey_14AkujRvgt3XOoAv6mRtHNwsYMmtnoCG__QdcJkb2Q","SendPushNotificationConfirmation":true,"ConfirmationMessege":"Welcome to PlayFab!"},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"Unauthorized"}}", source: file:///android_asset/www/scripts/realpush/realpush.service.js (64)

any comment appreciated !

thanks

 

 

 

 

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Since the response is that the authentication header is missing, that'd be the place to look. Clearly, there are some pretty significant differences in your implementation, so it's hard to say why the header isn't being delivered properly. Can you get a netmon or wireshark capture of the message, to see what's actually being sent?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bda2206@gmail.com avatar image
bda2206@gmail.com answered

yeah I've been toying with wiresharking it (urgh). theres a lot of comment about $http breaking POST requests and making it x-www-form-urlencoded to make things work. do you have an example of what I should be looking to see on the wire?

 

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

No, but Wireshark does at least make it easy. The HTTP headers are included by default, so all you have to do is open the HTTP in the decode pane in their interface, to see it. If you can get that, feel free to post the info here, and we can have a look.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bda2206@gmail.com avatar image
bda2206@gmail.com answered

the headers I've set are not being sent. 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bda2206@gmail.com avatar image
bda2206@gmail.com answered

got it. installed a packet sniffer on my phone called "Packet Capture"

my executerequest code looks like this, interestingly the shorthand version of $http seemingly doesn't work.

 

ExecuteRequest: function (completeUrl, data, authkey, authValue, callback) {
                
if (callback != null && typeof (callback) != "function")
throw "Callback must be null or a function";
if (data == null)
data = {};

var startTime = new Date();
var requestBody = data;

var requestheaders = {
'Content-Type': 'application/json; charset=utf-8',
'X-PlayFabSDK': 'JavaScriptSDK-' + PlayFab._internalSettings.sdkVersion
}
if (authkey != null)
requestheaders[authkey] = authValue;

console.log("executerequest headers" + JSON.stringify(requestheaders));
$http({
                
method: 'POST',
url: completeUrl,
data: requestBody,
headers:requestheaders })
.success(function(result){
callback(result, null);
}).error(function(e){
// error.CallBackTimeMS = new Date() - startTime;
callback(null, e);
}).catch(function(e){
var error = {
code: 503, // Service Unavailable
status: "Service Unavailable",
error: "Connection error",
errorCode: 2, // PlayFabErrorCode.ConnectionError
errorMessage: e
};
// result.CallBackTimeMS = new Date() - startTime;
callback(null, error);
});
}

 

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

The missing header in your call would indeed be the problem, then. Since we don't provide an SDK which matches what you're building yet, I'm afraid we're not going to be able to assist much with debugging of this, though if you want to share your project with us, we can have see about having a look when we can.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bda2206@gmail.com avatar image
bda2206@gmail.com answered

that was a working executerequest, posted for anyone who follows in the ionic path, the rest of the code was pretty much cut n paste from the javascript. I've logged in, registered for push and sent a push to the device successfully.  fighting css now!

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Ah, I see - congratulations! Let us know if you run into any other issues.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.