gutter/hybridauth
Composer 安装命令:
composer require gutter/hybridauth
包简介
hybridauth/hybridauth integration for Nette Framework
README 文档
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');
}
}
统计信息
- 总下载量: 2.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-04-18