Search code examples
.htaccesscodeigniterhostingssl-certificatefacebook-apps

Facebook APP with Shared SSL in codeIgniter


I have a host with shared ssl in hostgator.com, I uploaded codeIgniter site in public_html(root) directory. I want to develop a website as well as facebook application. website run successful with 'login with facebook' while running a facebook app, it gives an url redirect error.

This is http url

 url(Website): http://example.org/ 

and secure url is

 https://in9.hostgator.in/~username/

In facebook app configuration,

  canvas url :  http://example.org/
  Secure Canvas URL : https://in9.hostgator.in/~username/ (Work in url)

When i have run facebook application, facebook gives an error :

    API Error Code: 191
    API Error Description: The specified URL is not owned by the application
    Error Message: Invalid redirect_uri: Given URL is not permitted by the application configuration.

In application, there is no .htaccess file for redirecting or removing index.php in root directory.

I have run this base controller code :

    public function __construct()
{
    parent::__construct();
    $this->load->library("session");
    $this->load->helper('cookie');

    parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
    $CI = & get_instance();
    $CI->config->load("facebook",TRUE);
    $config = $CI->config->item('facebook');
    $this->load->library('Facebook', $config);

}

/**
 * Index function
 * @access public
 * 
public function index()
{
    $userId = $this->facebook->getUser();
    // If user is not yet authenticated, the id will be zero

    if($userId == 0){
                    // Generate a login url
        $params = array(
                  'scope' => 'email,user_about_me, user_birthday, user_location');
        $url = $this->facebook->getLoginUrl($params);
        echo "<script type='text/javascript'>" . "top.location.href = '" . $url. "';</script>";
        }
    } 

When i print '$url' then redirect_url in query string is 'http://in9.hostgator.in/~username/', not redirect to https path.

I am confused, what is a mistake in code? or some wrong configuration in server or what?


Solution

  • Facebook applications have an "App Domains" setting too, the facebook sdk won't work if the canvas url's are not under the listed domains. Try to add both the example.org and the hostgator.in there.

    Alternatively you can use the facebook canvas url as the redirect uri, so if your facebook app's namespace is my-facebook-app then you can generate the login url like this:

    $this->facebook->getLoginUrl(array(
        'scope' => 'email,user_about_me, user_birthday, user_location',
        // change the last segment to you app's namespace
        'redirect_uri' => 'https://apps.facebook.com/my-facebook-app/'
    ));
    

    With canvas applications this probably more feasible since because if the redirect uri points directly to your secure canvas url, the users will "loose" facebook when they authenticate.