Facebooks OAuth dialog doesn't close properly in IE 11 - facebook

I'm using FB Client Api for Oauth authentication
All necessary data after login is recieved while authentication dialog becomes blank and doesn't close after successfull authentication. This behavior is only specific for IE 11. The rest of browsers close Oauth dialog successfully.
Here is init code for FB SDK:
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
},
This is my init code for FB Login
function fbAsyncInit() {
FB.init({
appId: options.applicationId, // App ID
status : true,
xfbml : true
});
FB.getLoginStatus( callback );
}
window.fbAsyncInit = window.fbAsyncInit || fbAsyncInit;
And the last but not least: authorization function
authorize = function() {
var dfd = new $.Deferred();
FB.Event.subscribe( "auth.authResponseChange", function( response ) {
if ( response.status === "connected" ) {
dfd.resolve();
return;
} else {
FB.login(function() {
dfd.resolve();
});
}
});
FB.getLoginStatus(function( response ) {
if ( response && response.status === "connected" ) {
dfd.resolve();
return;
}
FB.login();
});
return dfd.promise();
};
Once again - I recieve all necessary events, problem is that dialog doesn't close after successfull authentication.

Related

How to use facebook token from cookie?

I can get facebook access token on client side of asp.net mvc application with method FB.getLoginStatus()
The token:
EAAFjVDcBGp4BABSnPzvjeR0ZCqEHExSRIGtvEIMPZCZABh****fk03WZCg10xaPJUs3ZCZAMTnP8
It's set token to cookies. I want to access it on server side, but on server I get it:
Kk9fbM-3d8ih4SpCfMddsj23BW2bqwPlll9LLs8ZYUE.eyJh****IjEwNzI4NDM4NjQ0OTI5MiJ9
Why? What should I do to get token from cookie?
UPDATED
Client code:
function checkLoginState() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected')
return;
FB.login();
});
}
window.fbAsyncInit = function() {
FB.init({
appId: #ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId],
cookie : true,
xfbml : true,
version : 'v2.8'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Server code:
var userToken = HttpContext.Current.Request.Cookies[String.Concat("fbsr_", ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId])].Value
The cookies doesn't contains access_token
After a day I founded solution here:
Problem getting access_token after migrating to OAuth 2.0

Facebook app is just posting content on my wall?

I have created a Facebook app which will share a link to users wall
but the issue is the link is posted on my wall but not on any other user's wall
i have put on live link Link to post on wall app
the code of app that will post on users wall is given below is there anything i need to approve it from the facebook or is there any mistake in my code please i need a real help any one could do ?
waiting for your kind response i am new to the Facebook API
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: '763390233734216', // App ID from the app dashboard
//channelUrl : '//local.facebook-test/channel.html', // Channel file for x-domain comms
status: true, // Check Facebook Login status
xfbml: true, // Look for social plugins on the page
oauth: true // Enable oauth authentication
});
// Additional initialization code such as adding Event Listeners goes here
FB.login(function(response) {
if (response.authResponse) {
console.log(response.authResponse.accessToken);
var params = {};
params['name'] = 'Seasons Canola';
params['description'] = 'Description';
params['link'] = 'http://vimeo.com/99708842';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'public_profile,email,publish_actions'
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

Facebook permissions window doesn't appear on tablets using JS SDK

I'm using the login code from Facebooks documentation:
This works fine in desktop browsers but on tablets the whole site tries to redirect to an https://m.facebook.com... URL instead of showing the permissions pop up. The page it redirects to just displays Error. Can pop ups not work in Facebook Javascript SDK?
<div id="fb-root"></div>
<script type="text/javascript">
var likesPage = false;
var addisPageId = 'XXXXXX';
window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
appId: 'XXXXXXX', // App ID from the app dashboard
channelUrl: '/channel.html', // Channel file for x-domain comms
status: true, // Check Facebook Login status
xfbml: true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_gb/all.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
function callLogin() {
FB.login(function (response) {
var access_token = FB.getAuthResponse()['accessToken'];
$("#at").val(access_token);
if (response.authResponse) {
FB.api('/me/likes?fields=id', function (response) {
for (var i = 0; i < response.data.length; i++) {
if (response.data[i].id == addisPageId) {
likesPage = true;
break;
}
}
if (likesPage) {
FB.api('/me', function (userInfo) {
document.getElementById("email").value = userInfo.email;
document.getElementById("fbId").value = userInfo.id;
document.getElementById("fbform").submit();
});
} else {
document.getElementById("dontLikePage").style.display = "inline";
}
});
} else {
window.parent.location = "https://www.facebook.com/XXXX";
}
}, { scope: 'user_likes,email,publish_stream' });
}
</script>
Had this issue a while a go. I got around it by using thee facebook login button https://developers.facebook.com/docs/reference/plugins/login/ this works fine on tablets but using the fb.login in javascript just errors because of the issue you described.

Access denied while redirecting back to application

This is my implementation of facebook login functionality using Facebook SDK.
<script type="text/javascript">
window.fbAsyncInit = function () {
// Initialize the SDK upon load
FB.init({
appId: '1xxxxxxxxxxxx', // App ID
channelUrl: '//' + window.location.hostname + '//Home/Index',
scope: 'id,name,gender,user_birthday,email,first_name,last_name,access_token',
status: true,
cookie: true,
xfbml: true
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', OnLogin);
};
// This method will be called after the user login into facebook.
function OnLogin(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
$('#AccessToken').attr('value', access_token);
$("#AuthenticatedWithFacebook").attr("value", true);
FB.api('/me', LoadValues);
}
else {
$("#AuthenticationToken").removeAttr('value');
$("#AuthenticatedWithFacebook").attr("value", false);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if (me.id) {
$("#UserId").attr("value", me.id);
$("#AuthenticationToken").attr("value", "facebook/" + me.id);
$("#FirstName").attr("value", me.first_name);
$("#LastName").attr("value", me.last_name);
$("#EmailAddress").attr("value", me.email);
}
}
</script>
<script>(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1xxxxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Login Pop-Up works just fine but after logging in I'm getting following exception:
Exception was thrown at line 38, column 184 in http://static.ak.fbcdn.net/rsrc.php/v2/yQ/r/Yax99g-1J46.js
0x80070005 - JavaScript runtime error: Access is denied.
I'm testing here on localhost (http://localhost:59777/) which I have configured in my Facebook application as well.

Facebook login button not redirecting

I can't seem to understand why I'm not being redirected to the appropriate page. It certainly exists. Instead of redirecting me, a screen pops up and just goes away after a second.
<div id='fb-root'></div>
<script>
window.fbAsyncInit = function()
{
FB.init({
appId: 'ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.login', function(response)
{
window.location = '/fb_redirect.php';
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/en_US/all.js#xfbml=1&appId=ID';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class='fb-login-button' data-show-faces='false' scope='email' data-width='200' data-max-rows='1'></div>
Instead of doing FB.Event.subscriber, try the following:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
if ( typeof response != 'undefined' && typeof response.authResponse != 'undefined' ) {
window.location = '/fb_redirect.php';
}
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
The function will return connected if the user is logged in, and it will then redirect them to any page your want. You can keep the FB.Event.subscriber function in there for users who need to login for the first time, and the above code will work for returning users.