I just wanted to let you know of my solution. I ended up using a combination of the javascript and using a redirect to the oauth login page. Using the MVC coding framework, it was pretty easy to get the user back to where they were at the time that the authentication was verified and redirected to FB for authentication if they haven't allowed the app yet. The FB object is created after including the facebook js libraries and calling the init method on it.
Here is the function I used (exposed as a method on the mvc application object--rename "applicationName" to your application's registered name to store the FB return tokens in your app's scope):
Code:
verifyFBStatus: function(loginTheUser, redirectToController, redirectToAction, additionalParams) {
console.log("social:verifyFBStatus");
//check to see if we have authorized through facebook
FB.getLoginStatus(function(response) {
if (response.session) {
//They are already logged in
console.log("User is authorized for facebook. ");
this.applicationName.fbAccessToken = response.session.access_token;
this.applicationName.fbSession = response.session.session_key;
this.applicationName.fbUserId = response.session.uid;
Ext.dispatch({controller: redirectToController, action: redirectToAction, params: additionalParams});
} else if(loginTheUser) {
// no user session available yet
console.log("user has not authorized for facebook yet, need to login");
// see http://developers.facebook.com/docs/guides/mobile/#web for info
// and http://developers.facebook.com/docs/reference/dialogs/oauth/
var redirectTo = encodeURI(document.location.href.split('?')[0].split('#')[0]);
if(redirectToController && redirectToController.length > 0) {
redirectTo = redirectTo + "&state=" + redirectToController + "," + redirectToAction;
if(additionalParams) {
redirectTo = redirectTo + "," + additionalParams
}
}
var appId = 'XXXXXXXXXXXXXXXX'; //prod app id
//put the part of the URL that differentiates your dev URI from the prod one, so you can test and have something in prod at the same time.
if(document.location.href.indexOf("dev") > -1)
appId = 'YYYYYYYYYYYYYYY' //dev app id
document.location.href = 'http://www.facebook.com/dialog/oauth?client_id=' + appId + '&redirect_uri=' + redirectTo + '&display=touch&scope=publish_stream&response_type=token';
}
});
},
the launch operation on the application looks at the query string parameters to determine if this is a return from facebook by checking for "access_token".
Code:
var code = this.getQueryStringParameter("access_token")
var error = this.getQueryStringParameter("error");
if(code == '' && error == '') {
//not coming back from facebook
Ext.dispatch({
controller: 'home',
action : 'index'
});
} else if(code.length > 0) {
//returned from facebook login popup. save fb properties and go redirect
this.fbAccessToken = spinapp.getQueryStringParameter("access_token");
// these vars are not returned on the querystring. Use FB.getLoginStatus(...) to get them
// this.fbSession = spinapp.getQueryStringParameter("session_key");
// this.fbUserId = spinapp.getQueryStringParameter("uid");
//get the return to from the state vars
var stateVars = spinapp.getQueryStringParameter("state");
var controllerAction = stateVars.split(",");
Ext.dispatch({controller: controllerAction[0], action: controllerAction[1], params: controllerAction[2]});
this.DelayLoadingMask();
} else {
//there was an error
alert("error returned from Facebook: " + error);
}
This uses a redirect and return for the login dialog. I'm currently looking in to using iframes for comments but have run in to an issue with scrolling when the comment is larger than screen size. I need to use iframe for comments since there is no comments dialog
If I find a solution for that, I'll post it here too.