├── .gitignore ├── .travis.yml ├── Module.php ├── README.md ├── bin └── createAutoloadSupport.php ├── build └── .gitignore ├── composer.json ├── composer.phar ├── config ├── autoload │ ├── .gitignore │ └── module.orgHeiglHybridAuth.test.php └── module.config.php ├── phpunit.xml.dist ├── src ├── Controller │ └── IndexController.php ├── DummyUserWrapper.php ├── Service │ ├── HybridAuthFactory.php │ ├── IndexControllerFactory.php │ ├── SessionFactory.php │ ├── UserFactory.php │ └── ViewHelperFactory.php ├── SocialAuthUserWrapper.php ├── UserInterface.php ├── UserToken.php ├── UserTokenInterface.php ├── UserWrapperFactory.php └── View │ └── Helper │ └── HybridAuth.php └── tests ├── Framework └── TestCase.php ├── Service ├── HybridAuthFactoryTest.php ├── IndexControllerFactoryTest.php ├── SessionFactoryTest.php └── UserFactoryTest.php ├── UserWrapperFactoryTest.php └── View └── Helper └── HybridAuthTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | atlassian-ide-plugin.xml 2 | phpunit.xml 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | matrix: 4 | include: 5 | - php: nightly 6 | - php: hhvm 7 | - php: 7.0 8 | env: 9 | - TEST_COVERAGE=true 10 | - php: 7.0 11 | env: 12 | - DEPS=latest 13 | - php: 7.0 14 | env: 15 | - DEPS=lowest 16 | - php: 7.1 17 | - php: 7.1 18 | env: 19 | - DEPS=latest 20 | - php: 7.1 21 | env: 22 | - DEPS=lowest 23 | - php: 5.6 24 | - php: 5.6 25 | env: 26 | - DEPS=lowest 27 | - php: 5.6 28 | env: 29 | - DEPS=latest 30 | - php: 5.5 31 | allow_failures: 32 | - php: hhvm 33 | - php: nightly 34 | - php: 5.5 35 | 36 | 37 | before_install: 38 | - travis_retry composer self-update 39 | 40 | install: 41 | - if [[ $DEPS == 'latest' ]]; then travis_retry composer update; fi 42 | - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable ; fi 43 | - travis_retry composer install 44 | 45 | script: 46 | - phpunit --coverage-text 47 | 48 | notifications: 49 | email: 50 | - andreas@heigl.org 51 | -------------------------------------------------------------------------------- /Module.php: -------------------------------------------------------------------------------- 1 | 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * @category MailProxy 24 | * @package OrgHeiglMailproxy 25 | * @author Andreas Heigl 26 | * @copyright 2011-2012 Andreas Heigl 27 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 28 | * @version 0.0 29 | * @since 06.03.2012 30 | * @link http://github.com/heiglandreas/mailproxyModule 31 | */ 32 | 33 | namespace OrgHeiglHybridAuth; 34 | 35 | use Zend\ModuleManager\ModuleManager, 36 | Zend\EventManager\StaticEventManager, 37 | Zend\Mvc\ModuleRouteListener; 38 | use OrgHeiglHybridAuth\View\Helper\HybridAuth as HybridAuthViewManager; 39 | 40 | 41 | /** 42 | * The Module-Provider 43 | * 44 | * @category HybridAuth 45 | * @author Andreas Heigl 46 | * @copyright 2011-2012 Andreas Heigl 47 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 48 | * @version 0.0 49 | * @since 06.03.2012 50 | * @link http://github.com/heiglandreas/HybridAuth 51 | */ 52 | class Module 53 | { 54 | // public function init(ModuleManager $moduleManager) 55 | // { 56 | // $events = StaticEventManager::getInstance(); 57 | // $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100); 58 | // $events->attach('loadModule', 'loadModule', function(){error_log('bar');}); 59 | // } 60 | 61 | public function initializeView($e) 62 | { 63 | // $app = $e->getParam('application'); 64 | // $locator = $app->getLocator(); 65 | // $renderer = $locator->get('Zend\View\HelperLoader'); 66 | // $renderer->registerPlugin('hybridauthinfo', 'OrgHeiglHybridAuth\View\Helper\HybridAuth'); 67 | $servicemanager = $e->getApplication()->getServiceManager(); 68 | $helperManager = $servicemanager->get('viewhelpermanager'); 69 | $helperManager->setFactory('hybridauthinfo', function() use ($helperManager) { 70 | return new HybridauthViewManager($helperManager); 71 | }); 72 | 73 | } 74 | 75 | public function onBootstrap($e) 76 | { 77 | // $e->getApplication()->getServiceManager()->get('translator'); 78 | $eventManager = $e->getApplication()->getEventManager(); 79 | $moduleRouteListener = new ModuleRouteListener(); 80 | $moduleRouteListener->attach($eventManager); 81 | 82 | $servicemanager = $e->getApplication()->getServiceManager(); 83 | $helperManager = $servicemanager->get('ViewHelperManager'); 84 | $router = $servicemanager->get('Application')->getMvcEvent(); 85 | $helperManager->setFactory('hybridauthinfo', function() use ($helperManager, $router) { 86 | return new HybridauthViewManager($helperManager, $router); 87 | }); 88 | 89 | } 90 | 91 | public function getConfig() 92 | { 93 | return include __DIR__ . '/config/module.config.php'; 94 | } 95 | 96 | public function getAutoloaderConfig() 97 | { 98 | $config = array( 99 | 'Zend\Loader\StandardAutoloader' => array( 100 | 'namespaces' => array( 101 | __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, 102 | 'Hybridauth' => dirname(dirname(__DIR__)) . "/vendor/hybridauth/hybridauth/Hybrid" 103 | ) 104 | ) 105 | ); 106 | 107 | if (file_exists(__DIR__ . '/autoload_classmap.php')) { 108 | $config['Zend\Loader\ClassMapAutoloader'] = array(__DIR__ . '/autoload_classmap.php'); 109 | } 110 | 111 | return $config; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OrgHeiglHybridAuth 2 | 3 | [![Join the chat at https://gitter.im/heiglandreas/HybridAuth](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/heiglandreas/HybridAuth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | [![Build Status](https://travis-ci.org/heiglandreas/HybridAuth.png?branch=master)](https://travis-ci.org/heiglandreas/HybridAuth) 6 | [![Code Climate](https://codeclimate.com/github/heiglandreas/HybridAuth/badges/gpa.svg)](https://codeclimate.com/github/heiglandreas/HybridAuth) 7 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/heiglandreas/HybridAuth/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/heiglandreas/HybridAuth/?branch=master) 8 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f98bc80bacff432b81d7d3ee84248901)](https://www.codacy.com/app/github_70/HybridAuth?utm_source=github.com&utm_medium=referral&utm_content=heiglandreas/HybridAuth&utm_campaign=Badge_Grade) 9 | [![Coverage Status](https://coveralls.io/repos/github/heiglandreas/HybridAuth/badge.svg?branch=master)](https://coveralls.io/github/heiglandreas/HybridAuth?branch=master) 10 | 11 | [![Dependency Status](https://www.versioneye.com/user/projects/58a31cce940b230036768774/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/58a31cce940b230036768774) 12 | [![Total Downloads](https://poser.pugx.org/org_heigl/hybridauth/downloads.png)](https://packagist.org/packages/org_heigl/hybridauth) 13 | [![Latest Stable Version](https://poser.pugx.org/org_heigl/hybridauth/v/stable.png)](https://packagist.org/packages/org_heigl/hybridauth) 14 | [![Stories in Ready](https://badge.waffle.io/heiglandreas/HybridAuth.png?label=ready)](https://waffle.io/heiglandreas/HybridAuth) 15 | 16 | Use the SocialConnect-Library to create an absolute lightweight Authentication-Layer 17 | for your ZendFramework3-App 18 | 19 | You can login with all [supported SocialNetwork-Logins](https://github.com/SocialConnect/auth). 20 | The network and a user-object holding id, name, mail and language will be stored in the session. If you already have 21 | SocialNetwork users in your application you can use these to authorize your users. 22 | 23 | ## Requirements 24 | 25 | * The [SocialConnect-Library](https://github.com/SocialConnect/auth). This lib uses the version 3 which is not (yet) stable! 26 | * Zend Framework3 (well, obvious, isn't it?) 27 | 28 | ## Usage 29 | 30 | 1. In your application.conf-file add the Module to the list of modules 31 | 2. Copy the file ```vendor/org_heigl/hybridauth/config/autoload/module-orgHeiglHybridAuth.local.php``` to your 32 | applications ```config/autoload```-directory and adapt as appropriate. That might look like this: 33 | 34 | ```php 35 | return [ 36 | 'OrgHeiglHybridAuth' => [ 37 | 'socialAuth' => [ 38 | 'redirectUri' => 'http://localhost:8080/authenticate/backend', 39 | 'provider' => [ 40 | 'twitter' => [ 41 | 'applicationId' => '', 42 | 'applicationSecret' => '', 43 | 'scope' => ['email'], 44 | ], 45 | 'github' => [ 46 | 'applicationId' => '', 47 | 'applicationSecret' => '', 48 | 'scope' => ['email'], 49 | ], 50 | ], 51 | ], 52 | 'session_name' => 'orgheiglhybridauth', 53 | 'backend' => array('Twitter'), // could also be ['Twitter', 'Facebook'] 54 | // 'link' => '%1$s', // Will be either inserted as first parameter into item or simply returned as complete entry 55 | // 'item' => '%1$s', 56 | // 'itemlist' => '%1$s', 57 | // 'logincontainer' => '', 58 | // 'logoffcontainer' => '
  • %1$s
  • ', 59 | // 'logoffstring' => 'Logout %1$s', 60 | // 'loginstring' => 'Login%1$s', 61 | // 'listAttribs' => null, // Will be inserted as 2nd parameter into item 62 | // 'itemAttribs' => null, // Will be inserted as 2nd parameter into itemlist 63 | ] 64 | ]; 65 | ``` 66 | 67 | 3. Add this snippet to create a login-link 68 | 69 | ```php 70 | hybridauthinfo($provider); 73 | ?> 74 | ``` 75 | 76 | 4. After login you can access the user-info the following way: 77 | 78 | ```php 79 | $config = $this->getServiceLocator()->get('Config'); 80 | $config = $config['OrgHeiglHybridAuth']; 81 | $hybridAuth = new Hybridauth($config['hybrid_auth']); 82 | 83 | $token = $this->getServiceLocator()->get('OrgHeiglHybridAuthToken'); 84 | if (! $token->isAuthenticated()) { 85 | echo 'No user logged in'; 86 | } 87 | /** @var OrgHeiglHybridAuth\UserToken $user */ 88 | echo $token->getDisplayName(); // The name of the logged in user 89 | echo $token->getUID(); // The internal UID of the used service 90 | echo $token->getMail(); // The mail-address the service provides 91 | echo $token->getLanguage(); // The language the service provides for the user 92 | echo $token->getService() // Should print out the Name of the service provider. 93 | ``` 94 | 95 | ## Installation 96 | 97 | ### composer 98 | 99 | This module is best installed using [composer](http://packagist.org/packages/org_heigl/hybridauth). 100 | For that, run the following command to add the library to your app: 101 | 102 | # Require the hybridauth-module 103 | composer require org_heigl/hybridauth 104 | 105 | If you want to use more than one authentication-provider you should instead run this: 106 | 107 | # Require the hybridauth-module 108 | composer require org_heigl/hybridauth:dev-feature/multipleProviders 109 | 110 | ### Manual installation 111 | 112 | So you want it the hard way? Sure you don't want to give composer a try? 113 | 114 | Then go figure it out. You might want to ask on the gitter channel or on IRC (freenode) 115 | but expect a reply along the line "use composer!" 116 | 117 | Note that you can either download the zip-files of the libraries or use the git submodule command to clone the 118 | libs into the appropriate folders. You should **not** simply use ```git clone ``` as that might 119 | interfere with your local git-repo (when you use one). The submodule approach makes Lib-updates easier bun can 120 | end in a lot of headaches due to the caveats of the submodule-command! I can not provide you with support in that case! 121 | Alternatively you can fork the project at [github](https://github.com/heiglandreas/OrgHeiglHybridAuth). 122 | 123 | ### Example Implementation. 124 | 125 | There is an example-implementation at https://hybridauth.heigl.org - The 126 | sourcecode is on github. 127 | -------------------------------------------------------------------------------- /bin/createAutoloadSupport.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 26 | * @copyright ©2015-2015 Andreas Heigl 27 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 28 | * @version 0.0 29 | * @since 03.05.15 30 | * @link https://github.com/heiglandreas/ 31 | */ 32 | exec('pwd', $result); 33 | $cwd = $result[0]; 34 | $VENDOR_FOLDER = realpath(getenv('VENDOR_FOLDER')); 35 | if (! $VENDOR_FOLDER) { 36 | $currentFolder = dir(__FILE__); 37 | $vendorPos = strpos($currentFolder, '/vendor/'); 38 | if (false !== $vendorPos) { 39 | $VENDOR_FOLDER = realpath(substr($currentFolder, 0, $vendorPos + 7)); 40 | } 41 | } 42 | if (! $VENDOR_FOLDER) { 43 | $VENDOR_FOLDER = realpath(dir(__FILE__) . '../vendor'); 44 | } 45 | if (! $VENDOR_FOLDER) { 46 | die ('No vendor-Folder found!'); 47 | } 48 | 49 | $cmd[] = 'cd "' . dirname(__FILE__) . '/../"'; 50 | $cmd[] = $VENDOR_FOLDER . '/zendframework/zendframework/bin/classmap_generator.php -o autoload_classmap.php ../../../hybridauth/hybridauth'; 51 | $cmd[] = $VENDOR_FOLDER . '/zendframework/zendframework/bin/classmap_generator.php -a -o autoload_classmap.php'; 52 | echo implode(' && ', $cmd); 53 | exec(implode(' && ', $cmd)); -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "org_heigl/hybridauth", 3 | "type" : "library", 4 | "description" : "Lightweight Authentication Module for Zend-Framework 2 using the hybridauth-library", 5 | "keywords" : [ "login","social network","user", "twitter", "facebook", "github", "zf2", "module"], 6 | "homepage" : "http://github.com/heiglandreas/HybridAuth", 7 | "license" : "MIT", 8 | "authors" : [ 9 | { 10 | "name" : "Andreas Heigl", 11 | "email" : "andreas@heigl.org", 12 | "homepage" : "http://andreas.heigl.org", 13 | "role" : "Developer" 14 | }], 15 | "require" : { 16 | "php": "^5.6 || ^7.0", 17 | "zendframework/zend-mvc": "^3.0", 18 | "zendframework/zend-servicemanager": "^3.0", 19 | "zendframework/zend-session": "^2.7 || ^3.0", 20 | "zendframework/zend-uri": "^2.5 || ^3.0", 21 | "zendframework/zend-view": "^2.7 || ^3.0", 22 | "socialconnect/auth": "^1.0", 23 | "guzzlehttp/guzzle": "^6.2" 24 | }, 25 | "require-dev" : { 26 | "mockery/mockery": "^0.9.7", 27 | "phpunit/phpunit": "^5.7" 28 | }, 29 | "autoload" : { 30 | "psr-4" : { 31 | "OrgHeiglHybridAuth\\" : "src/" 32 | }, 33 | "classmap": [ 34 | "./" 35 | ] 36 | }, 37 | "autoload-dev" : { 38 | "psr-4" : { 39 | "OrgHeiglHybridAuthTest\\" : "tests/" 40 | } 41 | }, 42 | "minimum-stability": "stable", 43 | "prefer-stable" : true 44 | } 45 | -------------------------------------------------------------------------------- /composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heiglandreas/HybridAuth/369a7c90baddceda64c681e08c91f1d75a50dda7/composer.phar -------------------------------------------------------------------------------- /config/autoload/.gitignore: -------------------------------------------------------------------------------- 1 | *.php 2 | ! *.php.dist 3 | -------------------------------------------------------------------------------- /config/autoload/module.orgHeiglHybridAuth.test.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | namespace OrgHeiglHybridAuth; 32 | 33 | return array('OrgHeiglHybridAuth' => array( 34 | 'hybrid_auth' => array( 35 | // 'base_url' => 'http://example.com/auth/backend', 36 | 'providers' => array( 37 | 'Twitter' => array('enabled' => false, 'keys' => array('key' => '', 'secret' => '')), 38 | ), 39 | 'debug_mode' => false, 40 | // For some reason Hybrid_Auth doesn't create file in a specified folder, be sure that it exists 41 | 'debug_file' => __DIR__ . '/hybrid_auth.log', 42 | ), 43 | 'session_name' => 'orgheiglhybridauth', 44 | )); 45 | -------------------------------------------------------------------------------- /config/module.config.php: -------------------------------------------------------------------------------- 1 | 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * @category HybridAuth 24 | * @author Andreas Heigl 25 | * @copyright 2011-2012 php.ug 26 | * @license http://www.opensource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 06.03.2012 29 | * @link http://github.com/heiglandreas/php.ug 30 | */ 31 | namespace OrgHeiglHybridAuth; 32 | 33 | use OrgHeiglHybridAuth\Controller\IndexController; 34 | use OrgHeiglHybridAuth\Service\HybridAuthFactory; 35 | use OrgHeiglHybridAuth\Service\IndexControllerFactory; 36 | use OrgHeiglHybridAuth\Service\SessionFactory; 37 | use OrgHeiglHybridAuth\Service\UserFactory; 38 | use OrgHeiglHybridAuth\Service\ViewHelperFactory; 39 | use OrgHeiglHybridAuth\View\Helper\HybridAuth; 40 | use SocialConnect\Common\Http\Client\ClientInterface; 41 | use SocialConnect\Common\Http\Client\Guzzle; 42 | use SocialConnect\Provider\Session\Session; 43 | use SocialConnect\Provider\Session\SessionInterface; 44 | 45 | return [ 46 | 'router' => [ 47 | 'routes' => [ 48 | 'hybridauth' => [ 49 | 'type' => 'Literal', 50 | 'options' => [ 51 | 'route' => '/authenticate', 52 | 'defaults' => [ 53 | '__NAMESPACE__' => 'OrgHeiglHybridAuth\Controller', 54 | 'controller' => 'IndexController', 55 | 'action' => 'login', 56 | ], 57 | ], 58 | 'may_terminate' => true, 59 | 'child_routes' => [ 60 | 'login' => [ 61 | 'type' => 'Segment', 62 | 'options' => [ 63 | 'route' => '/login/:provider[/:redirect]', 64 | 'defaults' => [ 65 | 'action' => 'login', 66 | 'redirect' => 'home' 67 | ], 68 | ], 69 | ], 70 | 'logout' => [ 71 | 'type' => 'Segment', 72 | 'options' => [ 73 | 'route' => '/logout[/:redirect]', 74 | 'defaults' => [ 75 | 'action' => 'logout', 76 | 'redirect' => 'home' 77 | ], 78 | ], 79 | ], 80 | 'backend' => [ 81 | 'type' => 'Segment', 82 | 'options' => [ 83 | 'route' => '/backend/:provider[/]', 84 | 'defaults' => [ 85 | 'action' => 'backend', 86 | 'redirect' => 'home', 87 | ], 88 | ], 89 | ] 90 | ], 91 | ], 92 | ], 93 | ], 94 | 'controllers' => [ 95 | 'factories' => [ 96 | IndexController::class => IndexControllerFactory::class, 97 | ], 98 | ], 99 | 'service_manager' => [ 100 | 'factories' => [ 101 | 'OrgHeiglHybridAuthSession' => SessionFactory::class, 102 | 'OrgHeiglHybridAuthBackend' => HybridAuthFactory::class, 103 | 'OrgHeiglHybridAuthToken' => UserFactory::class, 104 | ], 105 | 'invokables' => [ 106 | UserWrapperFactory::class => UserWrapperFactory::class, 107 | ClientInterface::class => Guzzle::class, 108 | SessionInterface::class => Session::class, 109 | ], 110 | ], 111 | 'view_helpers' => [ 112 | 'factories' => [ 113 | HybridAuth::class => ViewHelperFactory::class, 114 | ], 115 | 'aliases' => [ 116 | 'hybridauthinfo' => HybridAuth::class 117 | ] 118 | ], 119 | 'OrgHeiglHybridAuth' => [ 120 | 'socialAuth' => [ 121 | 'redirectUri' => 'http://localhost:8080/authenticate/backend', 122 | 'provider' => [ 123 | 'twitter' => [ 124 | 'applicationId' => '', 125 | 'applicationSecret' => '', 126 | 'scope' => ['email'], 127 | ], 128 | 'github' => [ 129 | 'applicationId' => '', 130 | 'applicationSecret' => '', 131 | 'scope' => ['email'], 132 | ], 133 | ], 134 | ], 135 | 'backend' => 'Twitter', 136 | // 'backend' => ['Twitter' => 'twitter'], 137 | // 'backend' => ['Twitter' => 'twitter', 'Facebook' => 'facebook', '...'], 138 | 'link' => '%1$s', // Will be either inserted as first parameter into item or simply returned as complete entry 139 | 'item' => '%1$s', 140 | 'itemlist' => '%1$s', 141 | 'logincontainer' => '', 142 | 'logoffcontainer' => '
  • %1$s
  • ', 143 | 'logoffstring' => 'Logout %1$s', 144 | 'loginstring' => 'Login%1$s', 145 | 'listAttribs' => ' class="dropdown-menu"', // Will be inserted as 2nd parameter into item 146 | 'itemAttribs' => null, // Will be inserted as 2nd parameter into itemlist 147 | ] 148 | ]; 149 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ./tests/ 5 | 6 | 7 | 8 | disable 9 | 10 | 11 | 12 | 13 | src 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/Controller/IndexController.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2012 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 27.12.12 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | namespace OrgHeiglHybridAuth\Controller; 32 | 33 | use Hybridauth\Hybridauth; 34 | use Hybridauth\Endpoint; 35 | use SocialConnect\Auth\Service; 36 | use Zend\Mvc\Controller\AbstractActionController; 37 | use Zend\Session\Container as SessionContainer; 38 | use OrgHeiglHybridAuth\UserWrapperFactory; 39 | 40 | /** 41 | * Login or out using a social service 42 | * 43 | * @category 44 | * @author Andreas Heigl 45 | * @copyright ©2012-2012 Andreas Heigl 46 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 47 | * @version 0.0 48 | * @since 27.12.12 49 | * @link https://github.com/heiglandreas/ 50 | */ 51 | class IndexController extends AbstractActionController 52 | { 53 | /** 54 | * Stores the HybridAuth-Instance 55 | * 56 | * @var Service $authenticator 57 | */ 58 | protected $authenticator = null; 59 | 60 | /** 61 | * Storage of the session-Container 62 | * 63 | * @var SessionContainer $session 64 | */ 65 | protected $session = null; 66 | 67 | /** 68 | * Storage of the UserProxyFactory 69 | * 70 | * @var UserWrapperFactory $userProxyFactory 71 | */ 72 | protected $userWrapperFactory = null; 73 | /** 74 | * Set the authenticator 75 | * 76 | * @param Service $authenticator The Authenticator-Backend 77 | * 78 | * @return IndexController 79 | */ 80 | public function setAuthenticator(Service $authenticator) 81 | { 82 | $this->authenticator = $authenticator; 83 | return $this; 84 | } 85 | 86 | /** 87 | * Set the session container 88 | * 89 | * @param SessionContainer $container The session-container to use for storing the authentication 90 | * 91 | * @return IndexController 92 | */ 93 | public function setSession(SessionContainer $container) 94 | { 95 | $this->session = $container; 96 | return $this; 97 | } 98 | 99 | /** 100 | * Set the userwrapper 101 | * 102 | * @param UserWrapperFactory $factory The ProxyFactory 103 | * 104 | * @return IndexController 105 | */ 106 | public function setUserWrapperFactory(UserWrapperFactory $factory) 107 | { 108 | $this->userWrapperFactory = $factory; 109 | return $this; 110 | } 111 | 112 | /** 113 | * login using twitter 114 | */ 115 | public function loginAction() 116 | { 117 | $providerName = $this->params()->fromRoute('provider'); 118 | $this->session->offsetSet('redirect', $this->params()->fromRoute('redirect')); 119 | 120 | $provider = $this->authenticator->getProvider($providerName); 121 | 122 | return $this->redirectTo($provider->makeAuthUrl()); 123 | } 124 | 125 | /** 126 | * Logout 127 | */ 128 | public function logoutAction() 129 | { 130 | $this->session->offsetSet('authenticated', false); 131 | $this->session->offsetSet('user', null); 132 | $this->session->offsetSet('backend', null); 133 | 134 | return $this->doRedirect(); 135 | } 136 | 137 | /** 138 | * Redirect to the last known URL 139 | * 140 | * @return boolean 141 | */ 142 | protected function doRedirect() 143 | { 144 | if (! $redirect = $this->session->offsetGet('redirect')) { 145 | $redirect = $this->getEvent()->getRouteMatch()->getParam('redirect'); 146 | } 147 | 148 | $this->session->offsetUnset('redirect'); 149 | $redirect = base64_decode($redirect); 150 | 151 | if (! $redirect) { 152 | $redirect = '/'; 153 | } 154 | 155 | if (preg_match('|://|', $redirect)) { 156 | $this->redirect()->toUrl($redirect); 157 | } else { 158 | $this->redirect()->toRoute($redirect); 159 | } 160 | return false; 161 | } 162 | 163 | public function redirectTo($uri) 164 | { 165 | $this->redirect()->toUrl($uri); 166 | } 167 | 168 | /** 169 | * Call the HybridAuth-Backend 170 | */ 171 | public function backendAction() 172 | { 173 | $providerName = $this->params()->fromRoute('provider'); 174 | 175 | $provider = $this->authenticator->getProvider($providerName); 176 | $accessToken = $provider->getAccessTokenByRequestParameters($_GET); 177 | 178 | if (! $accessToken) { 179 | $this->session->offsetSet('authenticated', false); 180 | $this->session->offsetSet('user', null); 181 | $this->session->offsetSet('backend', $providerName); 182 | 183 | return $this->doRedirect(); 184 | } 185 | 186 | $this->session->offsetSet('authenticated',true); 187 | $this->session->offsetSet('user', $this->userWrapperFactory->factory($provider->getIdentity($accessToken))); 188 | $this->session->offsetSet('backend', $providerName); 189 | 190 | return $this->doRedirect(); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/DummyUserWrapper.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | /** 35 | * This class works as proxy to the HybridAuth-User-Object 36 | * 37 | * @category HybridAuth 38 | * @author Andreas Heigl 39 | * @copyright ©2012-2013 Andreas Heigl 40 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 41 | * @version 0.0 42 | * @since 11.01.13 43 | * @link https://github.com/heiglandreas/HybridAuth 44 | */ 45 | class DummyUserWrapper implements UserInterface 46 | { 47 | /** 48 | * Get the ID of the user 49 | * 50 | * @return string 51 | */ 52 | public function getUID() 53 | { 54 | return ''; 55 | } 56 | 57 | /** 58 | * Get the name of the user 59 | * 60 | * @return string 61 | */ 62 | public function getName() 63 | { 64 | return ''; 65 | } 66 | 67 | /** 68 | * Get the eMail-Address of the user 69 | * 70 | * @return string 71 | */ 72 | public function getMail() 73 | { 74 | return ''; 75 | } 76 | 77 | /** 78 | * Get the language of the user 79 | * 80 | * @return string 81 | */ 82 | public function getLanguage() 83 | { 84 | return ''; 85 | } 86 | 87 | /** 88 | * Get the display-name of the user. 89 | */ 90 | public function getDisplayName() 91 | { 92 | return ''; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Service/HybridAuthFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\Service; 32 | 33 | use Interop\Container\ContainerInterface; 34 | use Interop\Container\Exception\ContainerException; 35 | use SocialConnect\Auth\Service; 36 | use SocialConnect\Common\Http\Client\ClientInterface; 37 | use SocialConnect\Provider\Session\SessionInterface; 38 | use Zend\ServiceManager\Exception\ServiceNotCreatedException; 39 | use Zend\ServiceManager\Exception\ServiceNotFoundException; 40 | use Zend\ServiceManager\Factory\FactoryInterface; 41 | use Zend\ServiceManager\ServiceLocatorInterface; 42 | 43 | /** 44 | * Create an instance of the HybridAuth 45 | * 46 | * @category HybridAuth 47 | * @author Andreas Heigl 48 | * @copyright ©2013-2013 Andreas Heigl 49 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 50 | * @version 0.0 51 | * @since 11.01.13 52 | * @link https://github.com/heiglandreas/HybridAuth 53 | */ 54 | class HybridAuthFactory implements FactoryInterface 55 | { 56 | /** 57 | * Create an object 58 | * 59 | * @param ContainerInterface $container 60 | * @param string $requestedName 61 | * @param null|array $options 62 | * 63 | * @return object 64 | * @throws ServiceNotFoundException if unable to resolve the service. 65 | * @throws ServiceNotCreatedException if an exception is raised when 66 | * creating a service. 67 | * @throws ContainerException if any other error occurs 68 | */ 69 | public function __invoke( 70 | ContainerInterface $container, 71 | $requestedName, 72 | array $options = null 73 | ) { 74 | $config = $container->get('Config'); 75 | $config = $config['OrgHeiglHybridAuth']; 76 | 77 | return new Service( 78 | $container->get(ClientInterface::class), 79 | $container->get(SessionInterface::class), 80 | $config['socialAuth'] 81 | ); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Service/IndexControllerFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\Service; 32 | 33 | use Interop\Container\ContainerInterface; 34 | use Interop\Container\Exception\ContainerException; 35 | use OrgHeiglHybridAuth\Controller\IndexController; 36 | use OrgHeiglHybridAuth\UserWrapperFactory; 37 | use Zend\ServiceManager\Exception\ServiceNotCreatedException; 38 | use Zend\ServiceManager\Exception\ServiceNotFoundException; 39 | use Zend\ServiceManager\Factory\FactoryInterface; 40 | 41 | /** 42 | * Create an instance of the session 43 | * 44 | * @category HybridAuth 45 | * @author Andreas Heigl 46 | * @copyright ©2012-2013 Andreas Heigl 47 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 48 | * @version 0.0 49 | * @since 11.01.13 50 | * @link https://github.com/heiglandreas/HybridAuth 51 | */ 52 | class IndexControllerFactory implements FactoryInterface 53 | { 54 | /** 55 | * Create an object 56 | * 57 | * @param ContainerInterface $container 58 | * @param string $requestedName 59 | * @param null|array $options 60 | * 61 | * @return object 62 | * @throws ServiceNotFoundException if unable to resolve the service. 63 | * @throws ServiceNotCreatedException if an exception is raised when 64 | * creating a service. 65 | * @throws ContainerException if any other error occurs 66 | */ 67 | public function __invoke( 68 | ContainerInterface $container, 69 | $requestedName, 70 | array $options = null 71 | ) { 72 | $authenticator = $container->get('OrgHeiglHybridAuthBackend'); 73 | $session = $container->get('OrgHeiglHybridAuthSession'); 74 | $wrapperFactory = $container->get(UserWrapperFactory::class); 75 | 76 | $controller = new IndexController(); 77 | $controller->setSession($session) 78 | ->setAuthenticator($authenticator) 79 | ->setUserWrapperFactory($wrapperFactory); 80 | return $controller; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Service/SessionFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\Service; 32 | 33 | use Interop\Container\ContainerInterface; 34 | use Interop\Container\Exception\ContainerException; 35 | use Zend\ServiceManager\Exception\ServiceNotCreatedException; 36 | use Zend\ServiceManager\Exception\ServiceNotFoundException; 37 | use Zend\Session\Container as SessionContainer; 38 | use Zend\ServiceManager\Factory\FactoryInterface; 39 | 40 | /** 41 | * Create an instance of the session 42 | * 43 | * @category HybridAuth 44 | * @author Andreas Heigl 45 | * @copyright ©2013-2013 Andreas Heigl 46 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 47 | * @version 0.0 48 | * @since 11.01.13 49 | * @link https://github.com/heiglandreas/HybridAuth 50 | */ 51 | class SessionFactory implements FactoryInterface 52 | { 53 | /** 54 | * Create an object 55 | * 56 | * @param ContainerInterface $container 57 | * @param string $requestedName 58 | * @param null|array $options 59 | * 60 | * @return object 61 | * @throws ServiceNotFoundException if unable to resolve the service. 62 | * @throws ServiceNotCreatedException if an exception is raised when 63 | * creating a service. 64 | * @throws ContainerException if any other error occurs 65 | */ 66 | public function __invoke( 67 | ContainerInterface $container, 68 | $requestedName, 69 | array $options = null 70 | ) { 71 | $config = $container->get('Config'); 72 | $config = $config['OrgHeiglHybridAuth']; 73 | 74 | return new SessionContainer($config['session_name']); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Service/UserFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\Service; 32 | 33 | use Interop\Container\ContainerInterface; 34 | use Interop\Container\Exception\ContainerException; 35 | use OrgHeiglHybridAuth\DummyUserWrapper; 36 | use OrgHeiglHybridAuth\UserToken; 37 | use Zend\ServiceManager\Exception\ServiceNotCreatedException; 38 | use Zend\ServiceManager\Exception\ServiceNotFoundException; 39 | use Zend\ServiceManager\Factory\FactoryInterface; 40 | 41 | /** 42 | * Create an instance of the HybridAuth 43 | * 44 | * @category HybridAuth 45 | * @author Andreas Heigl 46 | * @copyright ©2013-2013 Andreas Heigl 47 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 48 | * @version 0.0 49 | * @since 11.01.13 50 | * @link https://github.com/heiglandreas/HybridAuth 51 | */ 52 | class UserFactory implements FactoryInterface 53 | { 54 | /** 55 | * Create an object 56 | * 57 | * @param ContainerInterface $container 58 | * @param string $requestedName 59 | * @param null|array $options 60 | * 61 | * @return object 62 | * @throws ServiceNotFoundException if unable to resolve the service. 63 | * @throws ServiceNotCreatedException if an exception is raised when 64 | * creating a service. 65 | * @throws ContainerException if any other error occurs 66 | */ 67 | public function __invoke( 68 | ContainerInterface $container, 69 | $requestedName, 70 | array $options = null 71 | ) { 72 | $session = $container->get('OrgHeiglHybridAuthSession'); 73 | $user = new DummyUserWrapper(); 74 | $service = ''; 75 | if ($session->offsetExists('authenticated') && true === $session->offsetGet('authenticated')) { 76 | // Display Logged in information 77 | $user = $session->offsetGet('user'); 78 | $service = $session->offsetGet('backend'); 79 | } 80 | 81 | $userToken = new UserToken(); 82 | $userToken->setService($service) 83 | ->setUser($user); 84 | 85 | return $userToken; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Service/ViewHelperFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\Service; 32 | 33 | use Interop\Container\ContainerInterface; 34 | use Interop\Container\Exception\ContainerException; 35 | use OrgHeiglHybridAuth\View\Helper\HybridAuth; 36 | use Zend\ServiceManager\Factory\FactoryInterface; 37 | 38 | /** 39 | * Create an instance of the HybridAuth 40 | * 41 | * @category HybridAuth 42 | * @author Andreas Heigl 43 | * @copyright ©2013-2013 Andreas Heigl 44 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 45 | * @version 0.0 46 | * @since 11.01.13 47 | * @link https://github.com/heiglandreas/HybridAuth 48 | */ 49 | class ViewHelperFactory implements FactoryInterface 50 | { 51 | /** 52 | * Create an object 53 | * 54 | * @param ContainerInterface $container 55 | * @param string $requestedName 56 | * @param null|array $options 57 | * 58 | * @return object 59 | * @throws ServiceNotFoundException if unable to resolve the service. 60 | * @throws ServiceNotCreatedException if an exception is raised when 61 | * creating a service. 62 | * @throws ContainerException if any other error occurs 63 | */ 64 | public function __invoke( 65 | ContainerInterface $container, 66 | $requestedName, 67 | array $options = null 68 | ) { 69 | $config = $container->get('Config'); 70 | $url = $container->get('ViewHelperManager')->get('url'); 71 | $token = $container->get('OrgHeiglHybridAuthToken'); 72 | 73 | return new HybridAuth( 74 | $config['OrgHeiglHybridAuth'], 75 | $token, 76 | $url 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/SocialAuthUserWrapper.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | use Hybridauth\Entity\Profile; 35 | use OrgHeiglHybridAuth\UserInterface; 36 | use SocialConnect\Common\Entity\User; 37 | 38 | /** 39 | * This class works as proxy to the HybridAuth-User-Object 40 | * 41 | * @category HybridAuth 42 | * @author Andreas Heigl 43 | * @copyright ©2012-2013 Andreas Heigl 44 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 45 | * @version 0.0 46 | * @since 11.01.13 47 | * @link https://github.com/heiglandreas/HybridAuth 48 | */ 49 | class SocialAuthUserWrapper implements UserInterface 50 | { 51 | /** 52 | * @var \SocialConnect\Common\Entity\User 53 | */ 54 | private $user; 55 | 56 | public function __construct(User $user) 57 | { 58 | $this->user = $user; 59 | } 60 | 61 | /** 62 | * Get the ID of the user 63 | * 64 | * @return string 65 | */ 66 | public function getUID() 67 | { 68 | return $this->user->id; 69 | } 70 | 71 | /** 72 | * Get the name of the user 73 | * 74 | * @return string 75 | */ 76 | public function getName() 77 | { 78 | return $this->user->username; 79 | } 80 | 81 | /** 82 | * Get the eMail-Address of the user 83 | * 84 | * @return string 85 | */ 86 | public function getMail() 87 | { 88 | return $this->user->email; 89 | } 90 | 91 | /** 92 | * Get the language of the user 93 | * 94 | * @return string 95 | */ 96 | public function getLanguage() 97 | { 98 | return ''; 99 | } 100 | 101 | /** 102 | * Get the display-name of the user. 103 | */ 104 | public function getDisplayName() 105 | { 106 | if ($this->user->fullname) { 107 | return $this->user->fullname; 108 | } 109 | 110 | if (! $this->user->firstname && ! $this->user->lastname) { 111 | return $this->user->username; 112 | } 113 | 114 | if (! $this->user->firstname) { 115 | return $this->user->lastname; 116 | } 117 | 118 | return $this->user->firstname . ' ' . $this->user->lastname; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/UserInterface.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | /** 35 | * This interface describes methods to access user-informations 36 | * 37 | * @category HybridAuth 38 | * @author Andreas Heigl 39 | * @copyright ©2012-2013 Andreas Heigl 40 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 41 | * @version 0.0 42 | * @since 11.01.13 43 | * @link https://github.com/heiglandreas/HybridAuth 44 | */ 45 | interface UserInterface 46 | { 47 | /** 48 | * Get the ID of the user 49 | * 50 | * @return string 51 | */ 52 | public function getUID(); 53 | 54 | /** 55 | * Get the name of the user 56 | * 57 | * @return string 58 | */ 59 | public function getName(); 60 | 61 | /** 62 | * Get the eMail-Address of the user 63 | * 64 | * @return string 65 | */ 66 | public function getMail(); 67 | 68 | /** 69 | * Get the language of the user 70 | * 71 | * @return string 72 | */ 73 | public function getLanguage(); 74 | 75 | /** 76 | * Get the name to be displayed 77 | * 78 | * @return string 79 | */ 80 | public function getDisplayName(); 81 | } 82 | -------------------------------------------------------------------------------- /src/UserToken.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | use OrgHeiglHybridAuth\HybridAuthUserWrapper; 35 | use OrgHeiglHybridAuth\DummyUserWrapper; 36 | use OrgHeiglHybridAuth\UserTokenInterface; 37 | 38 | /** 39 | * This class works as proxy to the HybridAuth-User-Object 40 | * 41 | * @category HybridAuth 42 | * @author Andreas Heigl 43 | * @copyright ©2012-2013 Andreas Heigl 44 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 45 | * @version 0.0 46 | * @since 11.01.13 47 | * @link https://github.com/heiglandreas/HybridAuth 48 | */ 49 | class UserToken implements UserTokenInterface 50 | { 51 | /** 52 | * The HybridAuth-User-object 53 | * 54 | * @var HybridAuthUserWrapper $userProfile 55 | */ 56 | protected $user = null; 57 | 58 | /** 59 | * The service the user has been authenticated with 60 | * 61 | * @var string $service 62 | */ 63 | protected $service = ''; 64 | 65 | /** 66 | * Set the user-object 67 | * 68 | * @param HybridAuthUserWrapper $userProfile The userprofile to use 69 | * 70 | * @return UserToken 71 | */ 72 | public function setUser(UserInterface $user) 73 | { 74 | $this->user = $user; 75 | return $this; 76 | } 77 | 78 | /** 79 | * Set the service the user has been authenticated with 80 | * 81 | * @param string $service 82 | * 83 | * @return UserToken 84 | */ 85 | public function setService($service) 86 | { 87 | $this->service = strtolower($service); 88 | 89 | return $this; 90 | } 91 | 92 | /** 93 | * Get the ID of the user 94 | * 95 | * @return string 96 | */ 97 | public function getUID() 98 | { 99 | return $this->user->getUid(); 100 | } 101 | 102 | /** 103 | * Get the name of the user 104 | * 105 | * @return string 106 | */ 107 | public function getName() 108 | { 109 | return $this->user->getName(); 110 | } 111 | 112 | /** 113 | * Get the eMail-Address of the user 114 | * 115 | * @return string 116 | */ 117 | public function getMail() 118 | { 119 | return $this->user->getMail(); 120 | } 121 | 122 | /** 123 | * Get the language of the user 124 | * 125 | * @return string 126 | */ 127 | public function getLanguage() 128 | { 129 | return $this->user->getLanguage(); 130 | } 131 | 132 | /** 133 | * Get the display-name of the user. 134 | */ 135 | public function getDisplayName() 136 | { 137 | return $this->user->getDisplayName(); 138 | } 139 | 140 | /** 141 | * Get the service 142 | * 143 | * @see UserTokenInterface::getService 144 | * @return string 145 | */ 146 | public function getService() 147 | { 148 | return $this->service; 149 | } 150 | 151 | /** 152 | * Check whether the user has been authenticated or not 153 | * 154 | * @see UserTokenInterface::isAuthenticated 155 | * @return boolean 156 | */ 157 | public function isAuthenticated() 158 | { 159 | if (! $this->getService()) { 160 | return false; 161 | } 162 | 163 | if (__NAMESPACE__ . '\DummyUserWrapper' === get_class($this->user)) { 164 | return false; 165 | } 166 | 167 | return true; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/UserTokenInterface.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | /** 35 | * This interface describes methods to access user-informations 36 | * 37 | * @category HybridAuth 38 | * @author Andreas Heigl 39 | * @copyright ©2012-2013 Andreas Heigl 40 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 41 | * @version 0.0 42 | * @since 11.01.13 43 | * @link https://github.com/heiglandreas/HybridAuth 44 | */ 45 | interface UserTokenInterface extends UserInterface 46 | { 47 | /** 48 | * Get the service the user has been authenticated with 49 | * 50 | * This method has to return FALSE if no authentication has been performed 51 | * 52 | * @return string|false 53 | */ 54 | public function getService(); 55 | 56 | /** 57 | * Check whether the user has been authenticated at all. 58 | * 59 | * @return boolean 60 | */ 61 | public function isAuthenticated(); 62 | } 63 | -------------------------------------------------------------------------------- /src/UserWrapperFactory.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2012-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/HybridAuth 30 | */ 31 | 32 | namespace OrgHeiglHybridAuth; 33 | 34 | use SocialConnect\Common\Entity\User; 35 | 36 | /** 37 | * This class works as factory to get an Object implementing the UserInterface 38 | * 39 | * @category HybridAuth 40 | * @author Andreas Heigl 41 | * @copyright ©2012-2013 Andreas Heigl 42 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 43 | * @version 0.0 44 | * @since 11.01.13 45 | * @link https://github.com/heiglandreas/HybridAuth 46 | */ 47 | class UserWrapperFactory 48 | { 49 | /** 50 | * Create the user-Proxy according to the given User-Object 51 | * 52 | * @return UserInterface 53 | * @throws \UnexpectedValueException 54 | */ 55 | public function factory($userObject) 56 | { 57 | switch (get_class($userObject)) 58 | { 59 | case User::class: 60 | return new SocialAuthUserWrapper($userObject); 61 | break; 62 | case 'Hybridauth\\Entity\\Profile': 63 | case 'Hybridauth\\Entity\\Twitter\\Profile': 64 | $userProxy = new HybridAuthUserWrapper(); 65 | $userProxy->setUser($userObject); 66 | return $userProxy; 67 | break; 68 | default: 69 | return new DummyUserWrapper(); 70 | } 71 | 72 | throw new \UnexpectedValueException(sprintf( 73 | 'The given Object could not be found. Found "%s" instead', 74 | get_Class($userObject) 75 | )); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/View/Helper/HybridAuth.php: -------------------------------------------------------------------------------- 1 | 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * @category HybridAuth 24 | * @author Andreas Heigl 25 | * @copyright 2011-2012 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 05.12.2012 29 | * @link http://github.com/heiglandreas/OrgHeiglHybridAuth 30 | */ 31 | namespace OrgHeiglHybridAuth\View\Helper; 32 | 33 | use OrgHeiglHybridAuth\UserToken; 34 | use Zend\View\Helper\AbstractHelper; 35 | use Zend\View\Helper\Url; 36 | use Zend\ServiceManager\ServiceLocatorAwareInterface; 37 | 38 | /** 39 | * A view helper that either generates a link to a login-widget or a logout-link 40 | * 41 | * @category HybridAuth 42 | * @author Andreas Heigl 43 | * @copyright 2011-2012 Andreas Heigl 44 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 45 | * @version 0.0 46 | * @since 05.12.2012 47 | * @link http://github.com/heiglandreas/OrgHeiglHybridAuth 48 | */ 49 | class HybridAuth extends AbstractHelper 50 | { 51 | protected $config; 52 | 53 | protected $token; 54 | 55 | protected $urlHelper; 56 | 57 | public function __construct($config, UserToken $authToken, Url $urlHelper) 58 | { 59 | $this->config = $config; 60 | $this->token = $authToken; 61 | $this->urlHelper = $urlHelper; 62 | } 63 | /** 64 | * create a link to either 65 | * 66 | * @param string $provider The provider to be used 67 | * @param string $route The route to redirect to 68 | * 69 | * @return string 70 | */ 71 | public function __invoke($provider = null, $route = '') 72 | { 73 | $route = base64_encode($route); 74 | $providers = (array) $this->config['backend']; 75 | $urlHelper = $this->urlHelper; 76 | 77 | if ($this->token->isAuthenticated()) { 78 | // Display Logged in information 79 | 80 | $user = sprintf($this->config['logoffstring'], $this->token->getDisplayName()); 81 | $link = $urlHelper( 82 | 'hybridauth/logout', 83 | ['redirect' => $route] 84 | ); 85 | $link = sprintf($this->config['link'], $user, $link); 86 | return sprintf($this->config['logoffcontainer'], $link); 87 | } 88 | 89 | if (null !== $provider && in_array($provider, $providers)) { 90 | return $urlHelper( 91 | 'hybridauth/login', 92 | array('redirect' => $route, 'provider' => $provider) 93 | ); 94 | } 95 | 96 | if (1 == count($providers)) { 97 | return sprintf( 98 | $this->config['item'], 99 | sprintf( 100 | $this->config['link'], 101 | sprintf( 102 | $this->config['loginstring'], 103 | ' using ' . current($providers) 104 | ), 105 | $urlHelper( 106 | 'hybridauth/login', 107 | [ 108 | 'redirect' => $route, 109 | 'provider' => strtolower(current($providers)), 110 | ] 111 | ) 112 | ), 113 | null 114 | ); 115 | } 116 | 117 | $xhtml = array(); 118 | foreach ($providers as $name => $backend) { 119 | $link = $urlHelper( 120 | 'hybridauth/login', 121 | [ 122 | 'redirect' => $route, 123 | 'provider' => $backend 124 | ] 125 | ); 126 | $xhtml[] = sprintf( 127 | $this->config['item'], 128 | sprintf( 129 | $this->config['link'], 130 | (is_string($name)?$name:$backend), 131 | $link 132 | ), 133 | $this->config['itemAttribs'] 134 | ); 135 | } 136 | 137 | return sprintf( 138 | $this->config['logincontainer'], 139 | sprintf( 140 | $this->config['loginstring'], 141 | ' using' 142 | ), 143 | sprintf( 144 | $this->config['itemlist'], 145 | implode("\n",$xhtml), 146 | $this->config['listAttribs'] 147 | ) 148 | ); 149 | 150 | } 151 | 152 | /** 153 | * Get the backends 154 | * 155 | * @return array 156 | */ 157 | public function getBackends($backends = null) 158 | { 159 | if (null === $backends) { 160 | $backends = $this->config['backend']; 161 | } 162 | 163 | $backends = (array) $backends; 164 | 165 | return $backends; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /tests/Framework/TestCase.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest; 33 | 34 | use Interop\Container\ContainerInterface; 35 | use \PHPUnit_Framework_TestCase; 36 | use \Zend\Mvc\Router\Http\TreeRouteStack as HttpRouter; 37 | use \OrgHeiglHybridAuth\Service\HybridAuthFactory; 38 | use Zend\ServiceManager\Factory\FactoryInterface; 39 | use Mockery as M; 40 | 41 | class HybridAuthFactoryTest extends PHPUnit_Framework_TestCase 42 | { 43 | public function testSessionCreation() 44 | { 45 | $factory = new HybridAuthFactory(); 46 | $this->assertInstanceof(FactoryInterface::class, $factory); 47 | 48 | $_SERVER['SERVER_NAME'] = 'localhost'; 49 | $_SERVER['REQUEST_URI'] = 'http://localhost'; 50 | $_SERVER['HTTP_HOST'] = 'localhost'; 51 | 52 | $this->markTestIncomplete('Testing inomplete due to routing issues'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Service/IndexControllerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest; 33 | 34 | use Interop\Container\ContainerInterface; 35 | use \PHPUnit_Framework_TestCase; 36 | use \OrgHeiglHybridAuth\Service\IndexControllerFactory; 37 | use Zend\ServiceManager\Factory\FactoryInterface; 38 | use Mockery as M; 39 | 40 | class IndexControllerFactoryTest extends PHPUnit_Framework_TestCase 41 | { 42 | public function testSessionCreation() 43 | { 44 | $factory = new IndexControllerFactory(); 45 | $this->assertInstanceof(FactoryInterface::class, $factory); 46 | 47 | $_SERVER['SERVER_NAME'] = 'localhost'; 48 | $_SERVER['REQUEST_URI'] = 'http://localhost'; 49 | $_SERVER['HTTP_HOST'] = 'localhost'; 50 | 51 | $this->markTestIncomplete('Testing inomplete due to routing issues'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Service/SessionFactoryTest.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest; 33 | 34 | use Interop\Container\ContainerInterface; 35 | use \PHPUnit_Framework_TestCase; 36 | use \OrgHeiglHybridAuth\Service\SessionFactory; 37 | use Zend\ServiceManager\Factory\FactoryInterface; 38 | use Mockery as M; 39 | 40 | class SessionFactoryTest extends PHPUnit_Framework_TestCase 41 | { 42 | public function testSessionCreation() 43 | { 44 | $factory = new SessionFactory(); 45 | $this->assertInstanceof(FactoryInterface::class, $factory); 46 | $servicemanager = M::mock(ContainerInterface::class); 47 | $servicemanager->shouldReceive('get') 48 | ->with('Config') 49 | ->andReturn(['OrgHeiglHybridAuth' => ['session_name' => 'foo']]); 50 | 51 | $session = $factory($servicemanager, ''); 52 | $this->assertInstanceof('\Zend\Session\Container', $session); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Service/UserFactoryTest.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 28.10.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest; 33 | 34 | 35 | use Interop\Container\ContainerInterface; 36 | use OrgHeiglHybridAuth\DummyUserWrapper; 37 | use OrgHeiglHybridAuth\Service\UserFactory; 38 | use Mockery as M; 39 | use OrgHeiglHybridAuth\SocialAuthUserWrapper; 40 | use Zend\ServiceManager\Factory\FactoryInterface; 41 | 42 | class UserFactoryTest extends \PHPUnit_Framework_TestCase 43 | { 44 | 45 | public function testCreationOfUserTokenWithUnauthenticatedSession() 46 | { 47 | $factory = new UserFactory(); 48 | $this->assertInstanceof(FactoryInterface::class, $factory); 49 | $servicemanager = M::mock(ContainerInterface::class); 50 | $session = M::mock('\Zend\Session\Container') 51 | ->shouldReceive('offsetExists') 52 | ->once() 53 | ->with('authenticated') 54 | ->andReturn(false) 55 | ->mock(); 56 | $servicemanager->shouldReceive('get')->with('OrgHeiglHybridAuthSession')->andReturn($session); 57 | 58 | $token = $factory($servicemanager, ''); 59 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserToken', $token); 60 | $this->assertFalse($token->isAuthenticated()); 61 | $this->assertAttributeEquals(new DummyUserWrapper(), 'user', $token); 62 | $this->assertempty($token->getService()); 63 | } 64 | 65 | 66 | public function testCreationOfUserTokenWithAuthenticatedSessionWithInValidAuthentication() 67 | { 68 | $factory = new UserFactory(); 69 | $this->assertInstanceof(FactoryInterface::class, $factory); 70 | $servicemanager = M::mock(ContainerInterface::class); 71 | $session = M::mock('\Zend\Session\Container') 72 | ->shouldReceive('offsetExists') 73 | ->once() 74 | ->with('authenticated') 75 | ->andReturn(true)->mock(); 76 | $session->shouldReceive('offsetGet') 77 | ->once() 78 | ->with('authenticated') 79 | ->andReturn(false)->mock(); 80 | $servicemanager->shouldReceive('get')->with('OrgHeiglHybridAuthSession')->andReturn($session); 81 | 82 | $token = $factory($servicemanager, ''); 83 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserToken', $token); 84 | $this->assertFalse($token->isAuthenticated()); 85 | $this->assertAttributeEquals(new DummyUserWrapper(), 'user', $token); 86 | $this->assertempty($token->getService()); 87 | } 88 | 89 | public function testCreationOfUserTokenWithAuthenticatedSessionWithValidAuthentication() 90 | { 91 | $factory = new UserFactory(); 92 | $this->assertInstanceof(FactoryInterface::class, $factory); 93 | $servicemanager = M::mock(ContainerInterface::class); 94 | $user = M::mock(SocialAuthUserWrapper::class); 95 | $session = M::mock('\Zend\Session\Container') 96 | ->shouldReceive('offsetExists') 97 | ->once() 98 | ->with('authenticated') 99 | ->andReturn(true)->mock(); 100 | $session->shouldReceive('offsetGet') 101 | ->times(3) 102 | ->andReturn(true, $user, 'twitter')->mock(); 103 | $servicemanager->shouldReceive('get')->with('OrgHeiglHybridAuthSession')->andReturn($session); 104 | 105 | $token = $factory($servicemanager, ''); 106 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserToken', $token); 107 | $this->assertTrue($token->isAuthenticated()); 108 | $this->assertAttributeEquals($user, 'user', $token); 109 | $this->assertEquals('twitter', $token->getService()); 110 | } 111 | 112 | public function testCreationOfUserTokenWithAuthenticatedSessionWithValidAuthenticationAndMissingSessionParts() 113 | { 114 | $this->markTestIncomplete('Proper handling of invalid arguments especialy with non-user-objects is missing'); 115 | $factory = new UserFactory(); 116 | $this->assertInstanceof(FactoryInterface::class, $factory); 117 | $servicemanager = M::mock(ContainerInterface::class); 118 | $session = M::mock('\Zend\Session\Container') 119 | ->shouldReceive('offsetExists') 120 | ->once() 121 | ->with('authenticated') 122 | ->andReturn(true)->mock(); 123 | $session->shouldReceive('offsetGet') 124 | ->times(3) 125 | ->andReturn(true, null, null)->mock(); 126 | $servicemanager->shouldReceive('get')->with('OrgHeiglHybridAuthSession')->andReturn($session); 127 | 128 | $token = $factory($servicemanager, ''); 129 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserToken', $token); 130 | $this->assertFalse($token->isAuthenticated()); 131 | // $this->assertAttributeEquals('twitter', 'user', $token); 132 | // $this->assertEquals($user, $token->getService()); 133 | } 134 | 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /tests/UserWrapperFactoryTest.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 11.01.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest; 33 | 34 | use PHPUnit_Framework_TestCase; 35 | use OrgHeiglHybridAuth\UserWrapperFactory; 36 | use Hybridauth\Entity\Profile; 37 | use Mockery as M; 38 | use SocialConnect\Common\Entity\User; 39 | 40 | class UserProxyFactoryTest extends PHPUnit_Framework_TestCase 41 | { 42 | public function testCreationWithKnownUserObject() 43 | { 44 | $factory = new UserWrapperFactory(); 45 | $userObj = new User(); 46 | $obj = $factory->factory($userObj); 47 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserInterface', $obj); 48 | } 49 | 50 | public function testCreationWithUnknownUserObject() 51 | { 52 | $factory = new UserWrapperFactory(); 53 | $userObj = M::mock(User::class); 54 | $obj = $factory->factory($userObj); 55 | $this->assertInstanceof('\OrgHeiglHybridAuth\UserInterface', $obj); 56 | $this->assertInstanceof('\OrgHeiglHybridAuth\DummyUserWrapper', $obj); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/View/Helper/HybridAuthTest.php: -------------------------------------------------------------------------------- 1 | 25 | * @copyright ©2013-2013 Andreas Heigl 26 | * @license http://www.opesource.org/licenses/mit-license.php MIT-License 27 | * @version 0.0 28 | * @since 12.10.13 29 | * @link https://github.com/heiglandreas/ 30 | */ 31 | 32 | namespace OrgHeiglHybridAuthTest\View\Helper; 33 | 34 | use Mockery as M; 35 | use OrgHeiglHybridAuth\UserToken; 36 | use OrgHeiglHybridAuth\View\Helper\HybridAuth; 37 | use Zend\Mvc\Service\ServiceManagerConfig; 38 | use Zend\ServiceManager\ServiceManager; 39 | use Zend\View\Helper\Url; 40 | 41 | class HybridAuthTest extends \PHPUnit_Framework_TestCase 42 | { 43 | public function testSettingServiceLocators() 44 | { 45 | $token = M::mock(UserToken::class); 46 | $urlHelper = M::mock(Url::class); 47 | 48 | $viewHelper = new HybridAuth([], $token, $urlHelper); 49 | 50 | $this->assertAttributeEquals([], 'config', $viewHelper); 51 | $this->assertAttributeEquals($token, 'token', $viewHelper); 52 | $this->assertAttributeEquals($urlHelper, 'urlHelper', $viewHelper); 53 | } 54 | 55 | /** 56 | * @dataProvider gettingBackendsProvider 57 | */ 58 | public function testGettingBackends($backend, $expected) 59 | { 60 | $token = M::mock(UserToken::class); 61 | $urlHelper = M::mock(Url::class); 62 | 63 | $viewHelper = new HybridAuth(['backend' => $backend], $token, $urlHelper); 64 | $this->assertEquals($expected, $viewHelper->getBackends($backend)); 65 | 66 | } 67 | 68 | public function gettingBackendsProvider() 69 | { 70 | return array( 71 | array('backend', array('backend')), 72 | array(array('backend'), array('backend')), 73 | array(array('foo', 'bar'), array('foo', 'bar')), 74 | ); 75 | } 76 | } 77 | --------------------------------------------------------------------------------