venca-x/social-login
Composer 安装命令:
composer require venca-x/social-login
包简介
Nette addon. Login with social networks ( Faceboook, Google, Twitter )
README 文档
README
Nette addon for login with social networks
| Version | Facebook App API | PHP | Recommended Nette |
|---|---|---|---|
| dev-master | 8.0 or own | >= 7.2 (support 8.0) | Nette 3.0 |
| 1.2.x | 8.0 or own | >= 7.2 (support 8.0) | Nette 3.0 |
| 1.1.x | 2.6 | >= 7.0 | Nette 2.4 (Nette\SmartObject) |
| 1.0.x | 2.6 | >= 5.5 | Nette 2.4, 2.3 (Nette\Object) |
All permissions for Facebook fields
Installation
Install dev-master version for Nette 3.0:
composer require venca-x/social-login:dev-master
Install 1.2.x version for Nette 3.0 (Nette\SmartObject):
composer require venca-x/social-login:^1.2.0
Install 1.1.x version for Nette 2.4 (Nette\SmartObject):
composer require venca-x/social-login:^1.1.0
Install 1.0.x version for Nette 2.4 or Nette 2.3 (Nette\Object):
composer require venca-x/social-login:^1.0.0
Configuration
config.neon
parameters:
facebook:
appId: '123456789'
appSecret: '987654321'
callbackURL: 'http://www.muj-web.cz/homepage/facebook-login'
defaultFbGraphVersion: 'v8.0'
google:
clientId: '123456789'
clientSecret: '987654321'
callbackURL: 'http://www.muj-web.cz/homepage/google-login'
twitter:
consumerKey: '123456789'
consumerSecret: '987654321'
callbackURL: 'http://www.muj-web.cz/homepage/twitter-login'
nette:
session:
autoStart: true # default is smart
services:
...
- VencaX\SocialLogin({ facebook: %facebook%, google: %google%, twitter: %twitter% }, 'domain-social-login' )
Where 'domain-social-login' replace to your unique identifier (it's cookie name for last used services for login)
BasePresenter.php
use VencaX; /** @var VencaX\SocialLogin */ private $socialLogin; public function injectSocialLogin( VencaX\SocialLogin $socialLogin ) { $this->socialLogin = $socialLogin; //set scope $this->socialLogin->facebook->setScope( ['email'] ); $this->socialLogin->google->setScope( array( "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email" ) ); } public function renderIn() { //$facebookLoginUrl = $this->socialLogin->facebook->getLoginUrl(); //$googleLoginUrl = $this->socialLogin->google->getLoginUrl(); //$twitterLoginUrl = $this->socialLogin->twitter->getLoginUrl(); //dump( $this->socialLogin->getSocialLoginCookie() ); //$this->template->facebookLastLogin = $this->socialLogin->facebook->isThisServiceLastLogin(); //$this->template->googleLastLogin = $this->socialLogin->google->isThisServiceLastLogin(); //$this->template->twitterLastLogin = $this->socialLogin->twitter->isThisServiceLastLogin(); //... }
Layout for in.latte:
<a rel="nofollow" href="{$facebookLoginUrl}" {if $facebookLastLogin}class="last-login"{/if}><i class="fa fa-facebook-square fa-lg"></i></a> <a rel="nofollow" href="{$googleLoginUrl}" {if $googleLastLogin}class="last-login"{/if}><i class="fa fa-google-plus-square fa-lg"></i></a><br/> <a rel="nofollow" href="{plink User:twitterLogin}" {if $twitterLastLogin}class="last-login"{/if}><i class="fa fa-twitter-square fa-lg"></i></a><br/> <a rel="nofollow" href="{plink User:registration}"><i class="fa fa-plus-square fa-lg"></i> Zaregistrovat</a>
Simple login
HomepagePresenter.php
public function actionFacebookLogin() { try { $me = $this->socialLogin->facebook->getMe( array( FacebookLogin::ID, FacebookLogin::EMAIL, FacebookLogin::NAME, FacebookLogin::FIRST_NAME, FacebookLogin::LAST_NAME ) ); dump( $me ); exit; } catch( Exception $e ) { $this->flashMessage( $e->getMessage(), "alert-danger" ); $this->redirect("Homepage:default"); } } public function actionGoogleLogin( $code ) { try { $me = $this->socialLogin->google->getMe( $code ); dump( $me ); exit; } catch( Exception $e ) { $this->flashMessage( $e->getMessage(), "alert-danger" ); $this->redirect("Homepage:default"); } } //...
Simple logint with Twitter
public function actionTwitterLogin($oauth_token, $oauth_verifier) { try { $me = $this->socialLogin->twitter->getMe($oauth_token, $oauth_verifier); //$me = $this->socialLogin->twitter->getMe($oauth_token, $oauth_verifier, true);//when zou want user's email dump($me); exit; } catch (Exception $e) { $this->flashMessage($e->getMessage(), 'alert-danger'); $this->redirect('Homepage:default'); } }
Login with backlink
Use it when you want to redirect to specific URL after success login
HomepagePresenter.php
private $backlink = null; //render where are links to social networks public function renderIn() { if ($this->backlink) { $this->socialLogin->facebook->setState($this->backlink); $this->socialLogin->google->setState($this->backlink); } //$facebookLoginUrl = $this->socialLogin->facebook->getLoginUrl(); //$googleLoginUrl = $this->socialLogin->google->getLoginUrl(); //$twitterLoginUrl = $this->socialLogin->twitter->getLoginUrl(); //dump( $this->socialLogin->getSocialLoginCookie() ); //$this->template->facebookLastLogin = $this->socialLogin->facebook->isThisServiceLastLogin(); //$this->template->googleLastLogin = $this->socialLogin->google->isThisServiceLastLogin(); //$this->template->twitterLastLogin = $this->socialLogin->twitter->isThisServiceLastLogin(); } public function actionFacebookLogin($state = NULL) { try { if ($state) $this->backlink = $state; $me = $this->socialLogin->facebook->getMe(); //dump( $me ); //exit(); if($this->backlink != null) { $this->redirect($this->backlink); } } catch( Exception $e ) { $this->flashMessage( $e->getMessage(), "alert-danger" ); $this->redirect("Homepage:default"); } } public function actionGoogleLogin( $code, $state = NULL ) { try { if ($state) $this->backlink = $state; $me = $this->socialLogin->google->getMe( $code ); //dump( $me ); //exit(); if($this->backlink != null) { $this->redirect($this->backlink); } } catch( Exception $e ) { $this->flashMessage( $e->getMessage(), "alert-danger" ); $this->redirect("Homepage:default"); } } ...
Registration
Facebook Developers - create new website app. Full: Settings -> Web page -> Site URL : http://www.mypage.com
API Console - Google Code - create new project add Google+ API: APIs & auth -> APIs -> Google+ API set ON credentials: APIs & auth -> Credentials -> Crate new Client ID -> Web application
venca-x/social-login 适用场景与选型建议
venca-x/social-login 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 394.46k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2014 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「nette」 「Social Login」 「Facebook login」 「Google login」 「Twitter login」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 venca-x/social-login 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 venca-x/social-login 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 venca-x/social-login 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
LinkedIn integration for Social
Nette Framework adapter for I18n package
Build forms from schema
Asynchronous MQTT client built on React
Form with datetime support and Bootstrap 4 form renderer
统计信息
- 总下载量: 394.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-26