Wednesday, August 26, 2009

Fix for Facebook authentication on IE

What?
This is for Facebook developers who have faced this problem. If you are using an Facebook application to authenticate a user on a PHP website, the Facebook redirection on Internet Explorer specifically fails the login of the user. This is because the return URL returned by facebook specifically for IE is the appending of the

CallBack URL specified in the Application +
the Next parameter +
a "?" +
the auth_token parameter.


This results in Facebook redirecting to a wierd URL.

the Workaround
for this is to remove the next parameter from the facebook login URL.

http://www.facebook.com/login.php?api_key=<API KEY>&v=1.0&next=http%3A%2F%2Flocalhost%2Ftest%2F%2Ffacebook%3Fredir_domain%3Dexample.com

to
http://www.facebook.com/login.php?api_key=<API KEY>&v=1.0


For PHP websites the changes for the facebook.php are given below:
It must be similar changes for any of the other client API's.
This is accomplished by changing the line on facebook.php
facebook-platform/php/facebook.php

Change the following lines
public function require_login() {
if ($user = $this->get_loggedin_user()) {
return $user;
}
$this->redirect($this->get_login_url(self::current_url(), $this->in_frame())
);
}


to

  public function require_login() {
if ($user = $this->get_loggedin_user()) {
return $user;
}
$this->redirect($this->get_login_url('', $this->in_frame()));
}


The change is to remove the next parameter from the $this->get_login_url Call from within require_login member function of the Facebook class.

This seems to fix the problem of login.
This is not a bug in facebook as it is the intended functionality inside apps.

Happy developing..

0 comments: