michalsvec/nette-opauth

Nette 框架的 Opauth 扩展

v0.6.7 2015-09-30 19:32 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:03:57 UTC


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

路线图

  • 为各种提供商添加更多身份