I have PHP-Class to work with Facebook API:
class Social {
private $name;
private $context;
private $tocken;
public function check(){
$this->tocken = $this->context->getAccessToken(); // get current tocken
if (isset($_SESSION['fb_tocken']) AND !empty($_SESSION['fb_tocken'])){
// session tocken not null
if ($_SESSION['fb_tocken'] == $this->tocken){
// session tocken = current tocken
// update last active
return true;
} elseif ($this->tocken == APPLICATION_TOCKEN) {
// current tocken == default tocken
$this->logout();
} else {
// current tocken <> default tocken
$this->logout();
}
} else {
// session tocken is null
if ($this->tocken == APPLICATION_TOCKEN){
// current tocken is default
return false;
} else {
// current tocken is not default
if ($this->getUserInfo()){
// user registered - login action
if ($this->login())
return true;
else
return false;
} else {
// register new user
if ($this->register()){
if ($this->login()){
return true;
} else
return false;
} else
return false;
}
}
}
}
// ...
};
If user used alogritm:
1 - Login in facebook 2 - Login in application 3 - Logout from facebook 4 - Login in facebook 5 - Open application
Application Problem:
after fifth step my app can't authorize a user. But if user press 'refresh' he become authorized.