codenitive/laravel-oneauth — pull request #15 by fideloper (2012-09-01 16:48:16+00:00)
Title: php incomplete object from session (database driver)

Hello -

I'm using the MySQL database driver for Sessions in my Laravel build. When I retrieve the oneauth object from the Session, I receive and incomplete PHP object.

```php

//In controller:
$user = Session::get('oneauth');

//print_r($user); result:

Array
(
[token] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => OneAuth\OAuth2\Token\Access
[access_token:protected] => BAhbByIB6nsiZXhwaXJlc19hdCI6IjIwMTItMDktMTVUMTU6NTM6MzlaIiwidXNlcl9pZHMiOls5MzYzNzc1LDM4ODI1NjcsMTAyNzk5NDYsOTMwNDUz12345zMDQ2MDksMTA3MzE5OTAsMTI4NTIwNDhdLCJ2ZXJzaW9uIjoxLCJjbGllbnRfaWQiOiJjYmZkZmIxZDZhYzM1ZDcyMjBhYWMzMzcxNzFkODJjODJkNjcxNGZlIiwiYXBpX2RlYWRib2x0IjoiOGEwNzM3YjM2MmVmNzBlNDBlMDUxNDM0MzQxNTUwNGIifXU6CVRpbWUN7yEcwFcJe9Y=--0a42d0186b98c5baac5f6e9ed16120d945b0573f
[expires:protected] => 1347724419
[refresh_token:protected] => BAhbByIB6nsiZXhwaXJlc19hdCI6IjIwMjItMDktMDFUMTU6NTM6MzlaIiwidXNlcl9pZHMiOls5MzYzNzc1LDM4ODI1NjcsMTAyNzk5NDYsOTMwNDUz12345MTI4NTIwNDhdLCJ2ZXJzaW9uIjoxLCJjbGllbnRfaWQiOiJjYmZkZmIxZDZhYzM1ZDcyMjBhYWMzMzcxNzFkODJjODJkNjcxNGZlIiwiYXBpX2RlYWRib2x0IjoiOGEwNzM3YjM2MmVmNzBlNDBlMDUxNDM0MzQxNTUwNGIifXU6CVRpbWUNL6AewK0Xe9Y=--84cb21f969379f5ea45c151ca5bb278f78be71d8
[secret:protected] =>
[uid:protected] =>
[user:protected] =>
)

[info] => Array
(
[uid] => 123345
[name] => fideloper
[nickname] =>
[email] => example@email.com
[image] =>
[urls] => Array
(
)

)

[provider] => basecamp
)
```

To fix this, I must do:
```php
$user = unserialize(serialize($user));
```

I believe this is due to how the oneauth data is added to the session. See these for reference:
http://stackoverflow.com/questions/1055728/php-session-with-an-incomplete-object
http://stackoverflow.com/questions/2010427/php-php-incomplete-class-object-with-my-session-data

I believe the fix for this would be to *NOT* add an object directly to the session, but rather **add an array** of the same data.

**I propose this change:**
`bundles/oneauth/libraries/auth/core.php` line 66:

```php
Event::fire('oneauth.logged', array($client, $user_data));

$session_data = array(
'access_token' => $user_data['token']->access_token,
'expires' => $user_data['token']->expires,
'refresh_token' => $user_data['token']->refresh_token,
'secret' => $user_data['token']->secret,
'uid' => $user_data['token']->uid,
'user' => $user_data['token']->user,
);
$user_data['token'] = $session_data;

Session::put('oneauth', $user_data);
```

After code change, the session `oneauth` object becomes:

```php
Array
(
[token] => Array
(
[access_token] => BAhbByIB6nsiZXhwaXJlc19hdCI6IjIwMTItMDktMTVUMTY6MzE6MDJaIiwidXNlcl9pZHMiOls5MzYzNzc1LDM4ODI1NjcsMTAyNzk5NDYsOTMwNDUzNSwaasdfasdfasdfasdfMTI4NTIwNDhdLCJ2ZXJzaW9uIjoxLCJjbGllbnRfaWQiOiJjYmZkZmIxZDZhYzM1ZDcyMjBhYWMzMzcxNzasdfasdfasdlYWRib2x0IjoiOGEwNzM3YjM2MmVmNzBlNDBlMDUxNDM0MzQxNTUwNGIifXU6CVRpbWUN8CEcwM42IXw=--0c4e9024409bdb5408c1f1f7b10423dbe6750baa
[expires] => 1347726662
[refresh_token] => BAhbByIB6nsiZXhwaXJlc19hdCI6IjIwMjItMDktMDFUMTY6MzE6MDJaIiwidXNlcl9pZHMiOls5MzYzNzc1LDM4ODI1NjcsMTAyNzk5NDYsOTMwNDUzNSw5MasdfasdfasdfasdfasdfDhdLCJ2ZXJzaW9uIjoxLCJjbGllbnRfaWQiOiJjYmZkZmIxZDZhYzM1ZDcyMjBhYWMzMzcxNzFkODJjODJkNjcxNGZlIiwiYXBpX2RlYWRib2x0IjoiOGEwNzM3YjM2MmVmNzBlNDBlMDUxNDM0MzQxNTUwNGIifXasdfsdCVEIXw=--5d75c38980b9736396e7d91ae5686b31bc101d6d
[secret] =>
[uid] =>
[user] =>
)

[info] => Array
(
[uid] => 12345
[name] => fideloper
[nickname] =>
[email] => example@email.com
[image] =>
[urls] => Array
(
)

)

[provider] => basecamp
)
```

I can provide a pull request if desired.

Thanks!