org_heigl / hybridauth
Lightweight Authentication Module for Zend-Framework 2 using the hybridauth-library
Installs: 1 808
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 6
Forks: 8
Open Issues: 3
Requires
- php: ^5.6 || ^7.0
- guzzlehttp/guzzle: ^6.2
- socialconnect/auth: ^1.0
- zendframework/zend-mvc: ^3.0
- zendframework/zend-servicemanager: ^3.0
- zendframework/zend-session: ^2.7 || ^3.0
- zendframework/zend-uri: ^2.5 || ^3.0
- zendframework/zend-view: ^2.7 || ^3.0
Requires (Dev)
- mockery/mockery: ^0.9.7
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-10-23 09:48:16 UTC
README
Use the SocialConnect-Library to create an absolute lightweight Authentication-Layer for your ZendFramework3-App
You can login with all supported SocialNetwork-Logins. The network and a user-object holding id, name, mail and language will be stored in the session. If you already have SocialNetwork users in your application you can use these to authorize your users.
Requirements
- The SocialConnect-Library. This lib uses the version 3 which is not (yet) stable!
- Zend Framework3 (well, obvious, isn't it?)
Usage
-
In your application.conf-file add the Module to the list of modules
-
Copy the file
vendor/org_heigl/hybridauth/config/autoload/module-orgHeiglHybridAuth.local.php
to your applicationsconfig/autoload
-directory and adapt as appropriate. That might look like this:return [ 'OrgHeiglHybridAuth' => [ 'socialAuth' => [ 'redirectUri' => 'http://localhost:8080/authenticate/backend', 'provider' => [ 'twitter' => [ 'applicationId' => '', 'applicationSecret' => '', 'scope' => ['email'], ], 'github' => [ 'applicationId' => '', 'applicationSecret' => '', 'scope' => ['email'], ], ], ], 'session_name' => 'orgheiglhybridauth', 'backend' => array('Twitter'), // could also be ['Twitter', 'Facebook'] // 'link' => '<a class="hybridauth" href="%2$s">%1$s</a>', // Will be either inserted as first parameter into item or simply returned as complete entry // 'item' => '<li%2$s>%1$s</li>', // 'itemlist' => '<ul%2$s>%1$s</ul>', // 'logincontainer' => '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">%1$s<b class="caret"></b></a>%2$s</li>', // 'logoffcontainer' => '<li>%1$s</li>', // 'logoffstring' => 'Logout %1$s', // 'loginstring' => 'Login%1$s', // 'listAttribs' => null, // Will be inserted as 2nd parameter into item // 'itemAttribs' => null, // Will be inserted as 2nd parameter into itemlist ] ];
-
Add this snippet to create a login-link
<?php $provider = "Twitter"; echo $this->hybridauthinfo($provider); ?>
-
After login you can access the user-info the following way:
$config = $this->getServiceLocator()->get('Config'); $config = $config['OrgHeiglHybridAuth']; $hybridAuth = new Hybridauth($config['hybrid_auth']); $token = $this->getServiceLocator()->get('OrgHeiglHybridAuthToken'); if (! $token->isAuthenticated()) { echo 'No user logged in'; } /** @var OrgHeiglHybridAuth\UserToken $user */ echo $token->getDisplayName(); // The name of the logged in user echo $token->getUID(); // The internal UID of the used service echo $token->getMail(); // The mail-address the service provides echo $token->getLanguage(); // The language the service provides for the user echo $token->getService() // Should print out the Name of the service provider.
Installation
composer
This module is best installed using composer. For that, run the following command to add the library to your app:
# Require the hybridauth-module
composer require org_heigl/hybridauth
If you want to use more than one authentication-provider you should instead run this:
# Require the hybridauth-module
composer require org_heigl/hybridauth:dev-feature/multipleProviders
Manual installation
So you want it the hard way? Sure you don't want to give composer a try?
Then go figure it out. You might want to ask on the gitter channel or on IRC (freenode) but expect a reply along the line "use composer!"
Note that you can either download the zip-files of the libraries or use the git submodule command to clone the
libs into the appropriate folders. You should not simply use git clone <library> <target>
as that might
interfere with your local git-repo (when you use one). The submodule approach makes Lib-updates easier bun can
end in a lot of headaches due to the caveats of the submodule-command! I can not provide you with support in that case!
Alternatively you can fork the project at github.
Example Implementation.
There is an example-implementation at https://hybridauth.heigl.org - The sourcecode is on github.