I have FB login enabled on my website with the FB JDK. When I use it, it works perfectly: the dialog window opens, I authorize, and the authResponse is as expected. When another user uses it (who has not yet authorized the app, but is logged into FB), the login dialog appears for a brief second, and instantly disappears, and the response object has status not_authorized. Any ideas as to why the dialog might not be asking the user to authorize?
In my layout (Haml):
%body
#fb-root
:javascript
window.fbAsyncInit = function() {
FB._https = false;
FB.init({
appId : <App ID>
status : true,
cookie : true,
oauth : true,
xfbml : true
});
FB.getLoginStatus(function(response) {
if(window.reportFBstatus) {
reportFBstatus(response);
}
}, true);
};
// Load the SDK
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
The login link:
%a{href: '#', onclick: 'FB.login(window.reportFBstatus, {scope: "user_about_me"})'}
In the Coffeescript:
window.reportFBstatus = (response) ->
$.ajaxSetup({
headers:
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
})
console.log response # always shows status=not_authorized for other users
if response.status is 'connected'
auth = response.authResponse
$.post('/login', {fb_id: auth.userID, fb_token: auth.accessToken}, (data) ->
window.currentUser = data
)
The solution that worked for me was actually a bone-headed one--I'd forgotten to change the app from sandbox mode to live mode in developers app console on Facebook (click your app on the left). Alternatively, I could have added the people I want to be able to log in as developers or testers.
Hope that helps others!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With