i have problem when i try to make Facebook authentication in Kohana.
What i do is:
In kohana i have view file called loginview.php where i have embedded this code
href="https://www.facebook.com/dialog/oauth?client_id=341106515944015"&redirect_uri=http://verana.ge/fbauth/&scope=user_about_me&state=veranalast">
and in controller folder i have controller called fbauth.php where i have this code
public function action_index()
{
$app_id = "341106515944015";
$app_secret = "79f547b92f34f886cc8d51ca1a5d33e0";
$my_url = "http://verana.ge/";
// session_start(); <!-- commented because in Kohana the Session is already started -->
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST["state"] = 'veranalast') {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
}
but when i hit on facebook link and trying to connect i getting the error which says the following
ErrorException [ Warning ]: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=341106515944015&redirect_uri=http%3A%2F%2Fverana.ge%2F&client_secret=79f547b92f34f886cc8d51ca1a5d33e0&code=AQB9jQDcWXNVhPoxhOH-GyJ_0P0UQD9y5wfFy8cfP48TxvlX0VnycEWSpTOC0NWXTyCfssTUHCwFjmZdySy74zor_AQGvtzE5YCkB3asMBhWiiAJhesbFa_GrQIzT7UWiNrbl73CmVz5hell-shwrnavUviuDvpMqg6jCbMBHa6nb39xvidf-P5KOe4wlyR9TG8) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad APPPATH/classes/controller/fbauth.php [ 32 ] 27 $token_url = "https://graph.facebook.com/oauth/access_token?" 28 . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) 29 . "&client_secret=" . $app_secret . "&code=" . $code; 30 31 32 $response = file_get_contents($token_url); 33 34 $params = null; 35 36 parse_str($response, $params); 37
also for double check i created this function outside Kohana and it worked without problem.
what i did was that out side Kohana i created file named by index.php where i putted html a tag of Facebook authentication and next i created file named by testauth.php in which i putted as same code as i putted in fbauth.php and as i said it worked without problem.
may be where are simple way to figured it out but i don't know it. Please tell me how to fix it.
Any Ides?
Thank you in Advance