oshirowanen
oshirowanen

Reputation: 15965

Denying facebook authentication

I have made an application which allows a user to login using their facebook account. Everything works find if they click "allow" when asked if they want give my application permission to access certain details from their facebook account. However, when they click "deny", it just keeps looping and keeps asking them if they want to give permission to the application. How do I get it to go to another page when they click "deny" instead of it continously looping and asking the same question?

I've tried looking at the documentation, but can't seem to find what I'm after.

Before asking for permission, the following is executed, then if I click "don't allow", it just keeps looping through the code below until I click "allow":

<?php

session_start();

require("facebook.php");

$facebook = new Facebook(array(
    'appId'  => 'app id goes here',
    'secret' => 'secret goes here',
    'cookie' => true
));

$session = $facebook->getSession();

if(!empty($session)) {

    try{

        $uid = $facebook->getUser();
        $user = $facebook->api('/me');

        $_SESSION['returned'] = array("id" => $uid, "name" => $user["name"], "access_token" => $session['access_token']);

        header('Location: returned.php');
        exit;

    } catch (Exception $e) {

        echo "something is wrong";
        exit;

    }

} else {

    $login_url = $facebook->getLoginUrl();
    header("Location: ".$login_url);

}

Upvotes: 1

Views: 244

Answers (1)

uncreative
uncreative

Reputation: 1446

according to the api it will redirect the user to the page you provided: http://YOUR_URL?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.

In the page you redirect to check for url parameter "error" In addition on success there should be a url parameter "code" which you should verify exists before proceeding

if (isset($_GET['error'])) {
  header('Location: URL_TO_GO_IF_FAILED');
} else {
  // ... whatever you were doing before
}

Upvotes: 3

Related Questions