PDA

View Full Version : Facebook Authentication with Sencha Touch



whatadewitt
23 Aug 2011, 5:58 PM
Hi everyone,

I've been at it all night, and for the life of me I cannot figure out how to allow a user to authorize my application with their Facebook account on Sencha Touch...

I've read this http://www.sencha.com/forum/showthread.php?132839-Authenticate-with-Facebook-Connect-in-Sencha-Touch-App-Authorize-against-Rails-App, but I can't seem to get anywhere...

I have a button that I want the user to press to authenticate with Facebook... right now I am attempting to use their JS SDK, which is the closest I've managed to get thus far...


FB.getLoginStatus(function(response) {
if (!response.session) {
FB.ui({
method: "permissions.request",
}, function(data) {
console.log(data);
});
} else {
console.log(response.session.uid)
}
});


I can put that code in my handler, and if the user is currently logged into Facebook and has authorize the app I can easily get their user id... if they're not logged in I get about a million errors...

I've tried this...


Ext.Ajax.request({ url: 'http://www.facebook.com/dialog/oauth/client_id=APP_ID&redirect_uri=http://www.example.com/response&response_type=token',
method: 'GET',
callback: function(options, success, response) {
popup.update(response.responseText);
popup.show('pop');
}
});

But that gives me the following in the console

"XMLHttpRequest cannot load http://www.facebook.com/dialog/oauth/client_id=APP_ID&redirect_uri=http://www.example.com/response&response_type=token?_dc=1314151014369. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin." (obviously APP_ID is my Facebook application ID).

I thought this might be because I was running the app locally, but even moving it to a server threw a similar error.

I'm at my wits end here. I love this framework, but I am stuck on this issue and it's tried my patience long enough... if anyone has any insight or example code they could share with me, it would be much appreciated.

Thank you,

--d

tahir_rauf
8 Feb 2012, 5:33 AM
The reason is that if you do an ajax request through java script the server it will give you a cross domain issue. Because the services are hosted on a separate domain.

One possible solution is to use a proxy in between in that way it will go as a server side request and no cross browser issue will appear.

This will solve the cross browser issue, but this still not a standard solution. I am looking into the same thing to authenticate through sencha touch. Will let you know if I get something, if you have solved this problem, you can share with us.

Thanks,
Tahir Rauf