Browse Source

Social Extension (WIP)

- added social config vars in Aauth Config
- added Social Class
- added Social Controller
- enhanced Login & Register with Social Features
- updated tests for Social Module
- updated Account Language
v3-dev
REJack 6 years ago
parent
commit
584ae32b8e
  1. 43
      app/Config/Aauth.php
  2. 10
      app/Controllers/Account/Edit.php
  3. 10
      app/Controllers/Account/Home.php
  4. 5
      app/Controllers/Account/Login.php
  5. 5
      app/Controllers/Account/Register.php
  6. 170
      app/Controllers/Account/Social.php
  7. 5
      app/Language/en/Account.php
  8. 64
      app/Libraries/Aauth.php
  9. 286
      app/Libraries/Aauth/Social.php
  10. 10
      app/Views/Account/Edit.php
  11. 12
      app/Views/Account/Home.php
  12. 6
      app/Views/Account/Login.php
  13. 6
      app/Views/Account/Register.php
  14. 207
      tests/Aauth/Libraries/Aauth/SocialTest.php

43
app/Config/Aauth.php

@ -292,6 +292,49 @@ class Aauth extends BaseConfig
public $captchaSiteKey = '';
public $captchaSecret = '';
/*
|--------------------------------------------------------------------------
| Social Login Variables
|--------------------------------------------------------------------------
|
| 'socialEnabled'
|
| Enables the oAuth2 functionalities to login or createUser trough social
| logins like google, facebook, twitter, github and many more.
| (default: false)
|
| 'socialRemeber'
|
| Remember social login user.
| Available Options:
| - false (disabled)
| - true (use social expires date)
| - Relative date format (e.g. '+ 1 week', '+ 1 month') for details
| see http://php.net/manual/de/datetime.formats.relative.php
| (default: true)
|
| 'socialProviders'
|
| Social Provider list
| (default: [])
|
*/
public $socialEnabled = false;
public $socialRemember = true;
public $socialProviders = [];
// public $socialEnabled = true;
// public $socialRemember = true;
// public $socialProviders = [
// 'Facebook' => [
// 'enabled' => true,
// 'keys' => [
// 'id' => '307655649901891',
// 'secret' => 'fb814dea3a38d36aa66222efab35c337',
// ],
// ],
// ];
/*
|--------------------------------------------------------------------------
| Group Variables

10
app/Controllers/Account/Edit.php

@ -85,6 +85,16 @@ class Edit extends Controller
}
}
if ($this->config->socialEnabled)
{
$data['providers'] = [];
foreach ($this->aauth->getProviders() as $provider)
{
$data['providers'][$provider] = $this->aauth->getSocialIdentifier($provider, $userId);
}
}
$data['useUsername'] = $this->config->loginUseUsername;
echo view('Account/Edit', $data);

10
app/Controllers/Account/Home.php

@ -53,6 +53,16 @@ class Home extends Controller
{
$data['user'] = $this->aauth->getUser();
if ($this->config->socialEnabled)
{
$data['providers'] = [];
foreach ($this->aauth->getProviders() as $provider)
{
$data['providers'][$provider] = $this->aauth->getSocialIdentifier($provider, $data['user']['id']);
}
}
echo view('Account/Home', $data);
}
}

5
app/Controllers/Account/Login.php

@ -71,6 +71,11 @@ class Login extends Controller
'/assets/css/login.css'
];
if ($this->config->socialEnabled)
{
$data['providers'] = $this->aauth->getProviders();
}
echo view('Account/Login', $data);
}
}

5
app/Controllers/Account/Register.php

@ -74,6 +74,11 @@ class Register extends Controller
'/assets/css/login.css'
];
if ($this->config->socialEnabled)
{
$data['providers'] = $this->aauth->getProviders();
}
echo view('Account/Register', $data);
}
}

170
app/Controllers/Account/Social.php

@ -0,0 +1,170 @@
<?php
/**
* CodeIgniter-Aauth
*
* Aauth is a User Authorization Library for CodeIgniter 4.x, which aims to make
* easy some essential jobs such as login, permissions and access operations.
* Despite ease of use, it has also very advanced features like grouping,
* access management, public access etc..
*
* @package CodeIgniter-Aauth
* @author Emre Akay
* @author Raphael "REJack" Jackstadt
* @copyright 2014-2019 Emre Akay
* @license https://opensource.org/licenses/MIT MIT License
* @link https://github.com/emreakay/CodeIgniter-Aauth
*/
namespace App\Controllers\Account;
use CodeIgniter\Controller;
use Config\Aauth as AauthConfig;
use App\Libraries\Aauth;
use Config\Services;
/**
* Aauth Accont/Social Controller
*
* @package CodeIgniter-Aauth
*/
class Social extends Controller
{
/**
* Constructor
*/
public function __construct()
{
$this->config = new AauthConfig();
$this->aauth = new Aauth();
$this->request = Services::request();
helper('form');
}
/**
* Index
*
* @param string $provider Provider Name
*
* @return redirect
*/
public function connect(string $provider = null)
{
if ($provider)
{
session()->setFlashdata('social_provider', $provider);
}
else
{
$provider = session('social_provider');
}
if ($userId = $this->aauth->getUserId())
{
if ($this->aauth->authenticateProvider($provider, 'account/social/connect/'))
{
if ($userId = $this->aauth->getUserId())
{
helper('text');
$userProfile = $this->aauth->getSocialDetails($provider);
$password = random_string('alnum', (config('Aauth')->passwordMin + 2));
$username = preg_replace('/[^A-Za-z0-9]/', '', $userProfile->displayName);
$this->aauth->linkSocial($userId, $provider);
}
}
return redirect()->to(site_url('/account'));
}
return redirect()->to('/');
}
/**
* Index
*
* @param string $provider Provider Name
*
* @return redirect
*/
public function disconnect(string $provider)
{
if ($userId = $this->aauth->getUserId())
{
$this->aauth->unlinkSocial($userId, $provider);
return redirect()->to(site_url('/account'));
}
return redirect()->to('/');
}
/**
* Index
*
* @param string $provider Provider Name
*
* @return redirect
*/
public function login(string $provider = null)
{
if ($provider)
{
session()->setFlashdata('social_provider', $provider);
}
else
{
$provider = session('social_provider');
}
if ($this->aauth->authenticateProvider($provider, 'account/social/login/'))
{
if ($this->aauth->loginSocial($provider))
{
return redirect()->to(site_url('/account'));
}
}
return redirect()->to(site_url('/account/login'))->with('errors', lang('Aauth.notFoundUser'));
}
/**
* Index
*
* @param string $provider Provider Name
*
* @return redirect
*/
public function register(string $provider = null)
{
if ($provider)
{
session()->setFlashdata('social_provider', $provider);
}
else
{
$provider = session('social_provider');
}
if ($this->aauth->authenticateProvider($provider, 'account/social/register/'))
{
if (! $this->aauth->loginSocial($provider))
{
helper('text');
$userProfile = $this->aauth->getSocialDetails($provider);
$password = random_string('alnum', (config('Aauth')->passwordMin + 2));
$username = preg_replace('/[^A-Za-z0-9]/', '', $userProfile->displayName);
if ($userId = $this->aauth->createUser($userProfile->email, $password, $username))
{
$this->aauth->linkSocial($userId, $provider);
$this->aauth->loginSocial($provider);
return redirect()->to(site_url('/account'));
}
return redirect()->to(site_url('/account/register'))->with('errors', $this->aauth->printErrors('<br />', true));
}
return redirect()->to(site_url('/account'));
}
}
}

5
app/Language/en/Account.php

@ -28,12 +28,15 @@ return [
'homeText' => 'Account Details',
'homeLabelUsername' => 'Username',
'homeLabelEmail' => 'Email address',
'homeLabelSocial' => 'Connected Social Accounts',
'editHeader' => 'Edit Profile',
'editLabelUsername' => 'Username',
'editLabelEmail' => 'Email address',
'editLabelPassword' => 'Password',
'editLabelSubmit' => 'Save changes',
'editLabelSocialConnect' => 'Connect with ',
'editLabelSocialDisconnect' => 'Disconnect with ',
'linkBackToLogin' => 'Back to Login',
'linkLogin' => 'Login',
@ -46,6 +49,7 @@ return [
'loginLabelPassword' => 'Password',
'loginLabelRemember' => 'Remember me',
'loginLabelSubmit' => 'Login',
'loginLabelSocial' => 'Login with ',
'registerHeader' => 'Create new Account',
'registerLabelUsername' => 'Username',
@ -53,6 +57,7 @@ return [
'registerLabelPassword' => 'Password',
'registerLabelRemember' => 'Remember me',
'registerLabelSubmit' => 'Create Account',
'registerLabelSocial' => 'Create Account with ',
'registerRequired' => 'Required',
'verificationHeader' => 'Account Verification',

64
app/Libraries/Aauth.php

@ -131,6 +131,10 @@ class Aauth
if ($this->config->totpEnabled)
{
$this->modules = array_merge($this->config->modules, ['TOTP']);
if ($this->config->socialEnabled)
{
$this->modules = array_merge($this->modules, ['Social']);
}
$this->cachePermIds = [];
@ -378,23 +382,7 @@ class Aauth
if ($remember)
{
helper('text');
$expire = $this->config->loginRemember;
$userId = base64_encode($user['id']);
$randomString = random_string('alnum', 32);
$selectorString = random_string('alnum', 16);
$cookieData['name'] = $this->config->loginRememberCookie;
$cookieData['value'] = $userId . ';' . $randomString . ';' . $selectorString;
$cookieData['expire'] = YEAR;
$tokenData['user_id'] = $user['id'];
$tokenData['random_hash'] = password_hash($randomString, PASSWORD_DEFAULT);
$tokenData['selector_hash'] = password_hash($selectorString, PASSWORD_DEFAULT);
$tokenData['expires_at'] = date('Y-m-d H:i:s', strtotime($expire));
set_cookie($cookieData);
$loginTokenModel->insert($tokenData);
$this->generateRemember($user['id']);
}
$userModel->updateLastLogin($user['id']);
@ -428,6 +416,43 @@ class Aauth
}
}
/**
* Generate Remember
*
* @param integer $userId User Id
* @param string|integer $expire Expire Date, relative Date or Timestamp
*
* @return void
*/
protected function generateRemember(int $userId, string $expire = null)
{
helper('cookie');
helper('text');
if (! $expire)
{
$expire = $this->config->loginRemember;
}
$userIdEncoded = base64_encode($userId);
$randomString = random_string('alnum', 32);
$selectorString = random_string('alnum', 16);
$cookieData['name'] = $this->config->loginRememberCookie;
$cookieData['value'] = $userIdEncoded . ';' . $randomString . ';' . $selectorString;
$cookieData['expire'] = YEAR;
\Config\Services::response()->setCookie($cookieData)->send();
$tokenData['user_id'] = $userId;
$tokenData['random_hash'] = password_hash($randomString, PASSWORD_DEFAULT);
$tokenData['selector_hash'] = password_hash($selectorString, PASSWORD_DEFAULT);
$tokenData['expires_at'] = date('Y-m-d H:i:s', strtotime($expire));
$loginTokenModel = $this->getModel('LoginToken');
$loginTokenModel->insert($tokenData);
}
/**
* Logout
*
@ -515,6 +540,11 @@ class Aauth
{
$loginTokenModel->update($loginToken['id']);
if ($this->config->socialEnabled && $this->config->socialRemember)
{
$this->rebuildSocialStorage($loginToken['user_id']);
}
return $this->loginFast($loginToken['user_id']);
}
else

286
app/Libraries/Aauth/Social.php

@ -0,0 +1,286 @@
<?php
/**
* CodeIgniter-Aauth
*
* Aauth is a User Authorization Library for CodeIgniter 4.x, which aims to make
* easy some essential jobs such as login, permissions and access operations.
* Despite ease of use, it has also very advanced features like grouping,
* access management, public access etc..
*
* @package CodeIgniter-Aauth
* @author Emre Akay
* @author Raphael "REJack" Jackstadt
* @copyright 2014-2019 Emre Akay
* @license https://opensource.org/licenses/MIT MIT License
* @link https://github.com/emreakay/CodeIgniter-Aauth
* @since 3.0.0
*/
namespace App\Libraries\Aauth;
/**
* Aauth Social
*
* Class for handling social logins
*
* @package CodeIgniter-Aauth
*/
class Social extends \App\Libraries\Aauth
{
/**
* Variable to load HybridAuth config array
*
* @var array
*/
protected $configHybridAuth = [];
/**
* Variable to store HybridAuths storage name
*
* @var string
*/
protected $storageHybridAuth = 'HYBRIDAUTH::STORAGE';
/**
* Constructor
*
* Prepares config & session variable.
*
* @param \Config\Aauth $config Config Object
* @param \CodeIgniter\Session\Session $session Session Class
*
* @return void
*/
public function __construct(\Config\Aauth $config = null, \CodeIgniter\Session\Session $session = null)
{
parent::__construct($config, $session);
$this->configHybridAuth['providers'] = $config->socialProviders;
$this->configHybridAuth['callback'] = site_url();
}
/**
* Login Social
*
* @param string $provider Provider Name
*
* @return boolean|object
*/
public function loginSocial(string $provider = null)
{
$userProfile = $this->getSocialDetails($provider);
if ($userId = $this->getSocialUserId($provider, $userProfile->identifier))
{
$session = service('session');
$storage = $session->get($this->storageHybridAuth);
$this->updateSocialProviderIdentifier($userId, 'storage', json_encode($storage));
if ($this->config->socialRemember)
{
$expires = $this->config->socialRemember;
if ($expires === true)
{
$expires = $storage[strtolower($provider) . '.expires_at'];
}
$this->generateRemember($userId, $expires);
}
return $this->loginFast($userId);
}
return false;
}
/**
* Link Social
*
* @param integer $userId User Id
* @param string $provider Provider Name
*
* @return boolean
*/
public function linkSocial(int $userId, string $provider)
{
$userProfile = $this->getSocialDetails($provider);
$this->updateSocialStorage($userId);
return $this->updateSocialProviderIdentifier($userId, $provider, $userProfile->identifier);
}
/**
* Unlink Social
*
* @param integer $userId User Id
* @param string $provider Provider Name
*
* @return boolean
*/
public function unlinkSocial(int $userId, string $provider)
{
$session = service('session');
$session->remove($this->storageHybridAuth);
$userVariableModel = $this->getModel('UserVariable');
$userVariableModel->delete($userId, 'social_storage', true);
return $userVariableModel->delete($userId, 'social_' . strtolower($provider), true);
}
/**
* Rebuild Social Storage
*
* @param integer $userId User Id
*
* @return void
*/
public function rebuildSocialStorage(int $userId)
{
$userVariableModel = $this->getModel('UserVariable');
$providers = $this->getProviders();
if ($storedData = $userVariableModel->find($userId, 'social_storage', true))
{
$storedData = json_decode($storedData, true);
foreach ($providers as $provider)
{
if ($storedData[strtolower($provider) . '.expires_at'] > time())
{
$session = service('session');
$session->set($this->storageHybridAuth, $storedData);
}
}
}
}
/**
* Get Social User Id
*
* @param string $provider Provider Name
* @param string $identifier Identifier
*
* @return integer|boolean
*/
public function getSocialUserId(string $provider, string $identifier)
{
$userVariableModel = $this->getModel('UserVariable');
$whereArray = [
'data_key' => 'social_' . strtolower($provider),
'data_value' => $identifier,
'system' => 1,
];
if ($user = $userVariableModel->select('user_id')->where($whereArray)->first())
{
return (int) $user['user_id'];
}
return false;
}
/**
* Get Social Identifier
*
* @param string $provider Provider Name
* @param integer $userId User Id
*
* @return integer|boolean
*/
public function getSocialIdentifier(string $provider, int $userId)
{
$userVariableModel = $this->getModel('UserVariable');
$whereArray = [
'data_key' => 'social_' . strtolower($provider),
'user_id' => $userId,
'system' => 1,
];
if ($user = $userVariableModel->select('data_value')->where($whereArray)->first())
{
return $user['data_value'];
}
return false;
}
/**
* Get Social Details
*
* @param string $provider Provider Name
*
* @return \Hybridauth\User\Profile
*/
public function getSocialDetails(string $provider)
{
$hybridauth = new \Hybridauth\Hybridauth($this->configHybridAuth);
$adapter = $hybridauth->getAdapter($provider);
return $adapter->getUserProfile();
}
/**
* Get Providers
*
* @return array
*/
public function getProviders()
{
$hybridauth = new \Hybridauth\Hybridauth($this->configHybridAuth);
return $hybridauth->getProviders();
}
/**
* Authenticate Provider
*
* @param string $provider Provider Name
* @param string $callbackUrl Callback Link
*
* @return \Hybridauth\Adapter\AdapterInterface
*/
public function authenticateProvider(string $provider, string $callbackUrl)
{
$this->configHybridAuth['callback'] = site_url($callbackUrl);
$hybridauth = new \Hybridauth\Hybridauth($this->configHybridAuth);
$adapter = $hybridauth->authenticate($provider);
return $adapter;
}
/**
* Update Social Storage
*
* @param integer $userId User Id
*
* @return void
*/
private function updateSocialStorage(int $userId)
{
$session = service('session');
$storage = $session->get($this->storageHybridAuth);
$this->updateSocialProviderIdentifier($userId, 'storage', json_encode($storage));
}
/**
* Update Social Provider Identifier
*
* @param integer $userId User Id
* @param string $provider Provider Name
* @param string $identifier Identifier
*
* @return boolean
*/
private function updateSocialProviderIdentifier(int $userId, string $provider, string $identifier)
{
$userVariableModel = $this->getModel('UserVariable');
return $userVariableModel->save($userId, 'social_' . strtolower($provider), $identifier, true);
}
}

10
app/Views/Account/Edit.php

@ -31,6 +31,16 @@
</div>
<button class="btn btn-primary btn-block" type="submit"><?=lang('Account.editLabelSubmit')?></button>
<?= form_close() ?>
<?php if (isset($providers)): ?>
<div class="text-center">&mdash;</div>
<?php foreach ($providers as $provider => $state): ?>
<?php if ($state === false): ?>
<a href="<?= site_url('/account/social/connect/' . $provider) ?>" class="btn btn-secondary btn-block"><?=lang('Account.editLabelSocialConnect') . $provider ?></a>
<?php else: ?>
<a href="<?= site_url('/account/social/disconnect/' . $provider) ?>" class="btn btn-warning btn-block"><?=lang('Account.editLabelSocialDisconnect') . $provider ?></a>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?= $this->endSection() ?>

12
app/Views/Account/Home.php

@ -22,6 +22,18 @@
<?= $user['email'] ?>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<b><?= lang('Account.homeLabelSocial') ?></b>
</div>
<div class="col-sm-8">
<?php foreach ($providers as $provider => $state): ?>
<?php if ($state): ?>
<?= $provider ?> <br />
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
</div>

6
app/Views/Account/Login.php

@ -36,6 +36,12 @@
</div>
<button class="btn btn-primary btn-block" type="submit"><?=lang('Account.loginLabelSubmit')?></button>
<?= form_close() ?>
<?php if ($providers): ?>
<div class="text-center">&mdash;</div>
<?php foreach ($providers as $provider): ?>
<a href="<?= site_url('account/social/login/' . $provider) ?>" class="btn btn-info btn-block" type="submit"><?=lang('Account.loginLabelSocial') . $provider?></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="card-footer">
<div class="row">

6
app/Views/Account/Register.php

@ -34,6 +34,12 @@
<p class="small">* <?=lang('Account.registerRequired')?></p>
<button class="btn btn-primary btn-block" type="submit"><?=lang('Account.registerLabelSubmit')?></button>
<?= form_close() ?>
<?php if (isset($providers)): ?>
<div class="text-center">&mdash;</div>
<?php foreach ($providers as $provider): ?>
<a href="<?= site_url('/account/social/register/' . $provider) ?>" class="btn btn-info btn-block"><?=lang('Account.registerLabelSocial') . $provider ?></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="card-footer">
<div class="row">

207
tests/Aauth/Libraries/Aauth/SocialTest.php

@ -0,0 +1,207 @@
<?php namespace Tests\Aauth\Libraries\Aauth;
use Config\Aauth as AauthConfig;
use Config\Logger;
use Config\Services;
use Tests\Support\Log\TestLogger;
use Tests\Support\Session\MockSession;
use CodeIgniter\Session\Handlers\FileHandler;
use CodeIgniter\Test\CIDatabaseTestCase;
use App\Libraries\Aauth;
use App\Models\Aauth\UserModel;
use App\Models\Aauth\UserVariableModel;
use OTPHP\TOTP;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class SocialTest extends CIDatabaseTestCase
{
protected $refresh = true;
protected $basePath = FCPATH . '../app/Database/Migrations';
protected $namespace = 'App';
public function setUp()
{
parent::setUp();
$this->config = new AauthConfig();
$this->config->socialEnabled = true;
$this->library = new Aauth($this->config, null);
$_COOKIE = [];
$_SESSION = [];
}
public function tearDown()
{
}
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler',
'sessionCookieName' => 'ci_session',
'sessionExpiration' => 7200,
'sessionSavePath' => 'null',
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
];
$config = (object)$defaults;
$session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config);
$session->setLogger(new TestLogger(new Logger()));
$session->start();
return $session;
}
//--------------------------------------------------------------------
public function testUnlinkSocial()
{
$testArray = ['facebook.expires_at' => strtotime('+1 hour')];
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_storage',
'data_value' => json_encode($testArray),
'system' => true,
]);
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_facebook',
'data_value' => 'testing00testing00testing',
'system' => true,
]);
$config = new AauthConfig();
$session = $this->getInstance();
$config->socialEnabled = true;
$config->socialProviders = [
'Facebook' => [
'enabled' => true,
'keys' => [
'id' => 'testing',
'secret' => 'testing00testing00testing',
],
],
];
$this->library = new Aauth($config, $session);
$this->library->unlinkSocial(1, 'Facebook');
$this->dontSeeInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_storage',
'data_value' => json_encode($testArray),
'system' => true,
]);
$this->dontSeeInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_facebook',
'data_value' => 'testing00testing00testing',
'system' => true,
]);
$this->assertFalse(isset($_SESSION['HYBRIDAUTH::STORAGE']));
}
public function testGetSocialUserId()
{
$config = new AauthConfig();
$session = $this->getInstance();
$config->socialEnabled = true;
$this->library = new Aauth($config, $session);
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_testing',
'data_value' => 'testingidentifier',
'system' => true,
]);
$this->assertEquals(1, $this->library->getSocialUserId('testing', 'testingidentifier'));
$this->assertFalse($this->library->getSocialUserId('testing', 'none'));
}
public function testGetSocialIdentifier()
{
$config = new AauthConfig();
$session = $this->getInstance();
$config->socialEnabled = true;
$this->library = new Aauth($config, $session);
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_testing',
'data_value' => 'testingidentifier',
'system' => true,
]);
$this->assertEquals('testingidentifier', $this->library->getSocialIdentifier('testing', 1));
$this->assertFalse($this->library->getSocialIdentifier('testing99', 1));
}
public function testGetProviders()
{
$config = new AauthConfig();
$session = $this->getInstance();
$config->socialProviders = [
'Facebook' => [
'enabled' => true,
'keys' => [
'id' => 'testing',
'secret' => 'testing00testing00testing',
],
],
];
$config->socialEnabled = true;
$this->library = new Aauth($config, $session);
$this->assertEquals(['Facebook'], $this->library->getProviders());
}
public function testRebuildSocialStorage()
{
$testArray = ['facebook.expires_at' => strtotime('+1 hour')];
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 1,
'data_key' => 'social_storage',
'data_value' => json_encode($testArray),
'system' => true,
]);
$config = new AauthConfig();
$session = $this->getInstance();
$config->socialEnabled = true;
$config->socialProviders = [
'Facebook' => [
'enabled' => true,
'keys' => [
'id' => 'testing',
'secret' => 'testing00testing00testing',
],
],
];
$this->library = new Aauth($config, $session);
$this->library->rebuildSocialStorage(1);
$this->assertTrue(isset($_SESSION['HYBRIDAUTH::STORAGE']));
$this->assertEquals($testArray, $_SESSION['HYBRIDAUTH::STORAGE']);
}
}
Loading…
Cancel
Save