dopiaza / DPZFlickr

PHP API Kit for Flickr with support for OAuth
Other
30 stars 21 forks source link

It authenticates each time you enter a new user. #9

Open jparradog opened 8 years ago

jparradog commented 8 years ago

@dopiaza, made the implementation of the existosamente library, my only is incomveniente that whenever income, I must perform authentication, the library does not detect that there is already a oauth_token and oauth_verifier, and creates a new request for oauth_token, that I could not fix it, I would know if I'm doing something wrong or the library simply works.

Thank you.

jparradog commented 8 years ago

I solved saving the data generated by the class and stored in the variable $_SESSION [ 'FlickrSessionOauthData'], I left the saved data is variable and no longer authenticates each time it is used.

Wonneproppen commented 8 years ago

Hi jparradog, I have the same problem. Can you give me more advice how you solved it?

qayyumabro commented 7 years ago

Hi, I saved the session data to database and changed following two functions

private function setOauthData($key, $value)
{
    $data = @$_SESSION[self::SESSION_OAUTH_DATA];
    if (!is_array($data))
    {
        $data = array();
    }
    $data[$key] = $value;
    $_SESSION[self::SESSION_OAUTH_DATA] = $data;

    include('pdo.php');

    $jsonData = json_encode($data);

    $sql = "UPDATE users set session_data=:session_data WHERE id=:user_id LIMIT 1";
    $query = $handler->prepare($sql);
    $query->execute(array(':session_data'=>$jsonData, ':user_id'=>$this->user_id));
}

public function getOauthData($key)
{
    $val = NULL;
   /*$data = @$_SESSION[self::SESSION_OAUTH_DATA];
    if (is_array($data))
    {
        $val = @$data[$key];
    }*/

    include('db.pdo.php');

    $sql = "SELECT session_data FROM users WHERE id=:user_id LIMIT 1";
    $query = $handler->prepare($sql);
    $query->execute(array(':user_id'=>$this->user_id));

    if($row = $query->fetch())
    {
        $data = $row['session_data'];

        $jsonData = json_decode($data, true);

        if(isset($jsonData[$key]))
            return $jsonData[$key];
    }
    return null;
}

Not sure this method will work for long, can anyone check please?