michalsvec / nette-opauth
Nette 框架的 Opauth 扩展
v0.6.7
2015-09-30 19:32 UTC
Requires
- nette/nette: ~2.1
- opauth/facebook: *
- opauth/google: *
- opauth/linkedin: *
- opauth/opauth: *
- opauth/twitter: *
README
要求
由于它是 Nette 框架的 Opauth 扩展,因此需要以下内容
安装
更新 composer.json
"require": { "michalsvec/nette-opauth": "*" }
然后
$ composer install
更新 bootstrap.php
// add compiler extension $configurator->onCompile[] = function (\Nette\Config\Configurator $config, \Nette\Config\Compiler $compiler) { $compiler->addExtension('opauth', new NetteOpauth\DI\Extension()); }; // register routers \NetteOpauth\NetteOpauth::register($container->router);
检查路由是否按正确顺序排列(auth 路由在 common 路由之前)。并按示例更新 Auth 展示器。
然后您可以使用
{if Nette\Config\Configurator::detectDebugMode()} <a href="{plink Auth:callback, strategy => 'fake'}">Fake login</a><br/> {/if} <a href="{plink Auth:google}">Sign-in with Google</a><br/> <a href="{plink Auth:facebook}">Sign-in with Facebook</a><br/> <a href="{plink Auth:twitter}">Sign-in with Twitter</a><br/> <a href="{plink Auth:linkedin}">Sign-in with LinkedIn</a><br/>
在 config.neon 中配置
opauth:
path: '/auth/'
debug: false
callback_url: '{path}callback'
security_salt: '123abc456def'
callback_transport: 'session'
Strategy:
Facebook:
app_id: ''
app_secret: ''
Google:
client_id: ''
client_secret: ''
Twitter:
key: ''
secret: ''
LinkedIn:
api_key: ''
secret_key: ''
技巧和技巧
- opauth 需要公开的回调 URL 以正确重定向,因此无法在本地主机上使用它(除非是伪造的登录)。
- facebook
- 应用注册
- google
- 应用注册
- google ids 非常长(超过无符号 int),请注意这一点
- twitter
- 应用注册
- 不要提供电子邮件
- linkedin
- 应用注册
- 在应用注册中提供 OAuth 2.0 重定向 URL: http://yourdomain.tld/auth/linkedin/oauth2callback
- 为了获取电子邮件,请将 r_emailaddress 包含在作用域中,例如:'scope' => 'r_basicprofile r_emailaddress'。
路线图
- 为各种提供商添加更多身份