gutter / hybridauth
There is no license information available for the latest version (v2.0.5) of this package.
hybridauth/hybridauth integration for Nette Framework
v2.0.5
2018-04-18 14:32 UTC
Requires
- php: ^7.2
- hybridauth/hybridauth: ^2.6
- nette/di: ^2.4
This package is not auto-updated.
Last update: 2024-05-12 03:53:49 UTC
README
This is hybridauth/hybridauth integration for Nette Framework.
Installation
The best way to install Gutter\HybridAuth is via Composer:
$ composer require gutter/hybridauth
Usage
You can use the HybridAuth as an extension.
Configuration
First you have to set the extension up in config.neon
.
extensions:
hybridAuth: Gutter\HybridAuth\DI\HybridAuthExtension
hybridAuth:
base_url: https://myapp.com/auth/process
providers:
Google:
enabled: true
keys:
id: [your-google-key]
secret: [your-google-secret]
Facebook:
enabled: true
keys:
id: [your-facebook-key]
secret: [your-facebook-secret]
scope: email
Implementation
Then the implementation of /auth
controller could look like this:
class AuthPresenter extends BasePresenter
{
/** @var \Gutter\HybridAuth\Manager @inject */
public $hybridAuth;
/** @var AuthModel @inject */
public $model;
public function actionProcess()
{
$this->hybridAuth->process();
}
public function actionGoogle()
{
$adapter = $this->hybridAuth->authenticate('Google');
$userProfile = $adapter->getUserProfile();
$user = $this->model->getUserByEmail($userProfile->email);
if ($user) {
$this->login($user);
}
$this->redirect('Login:failed');
}
public function actionFacebook()
{
$adapter = $this->hybridAuth->authenticate('Facebook');
$userProfile = $adapter->getUserProfile();
$user = $this->model->getUserByEmail($userProfile->email);
if ($user) {
$this->login($user);
}
$this->redirect('Login:failed');
}
}