uzura8/fuel-packages-opauth

维护者

详细信息

github.com/uzura8/fuel-opauth

源代码

安装: 317

依赖项: 0

建议者: 0

安全: 0

星星: 0

观察者: 2

分支: 13

类型:fuel-package

dev-master 2015-03-02 11:35 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:57:01 UTC


README

FuelPHP 的 Opauth 包

FuelPHP 1.x 版本的 Opauth 包。Opauth 是一个多提供商身份验证框架。

Opauth 是一个多提供商身份验证框架。

需求

FuelPHP v1.x
Opauth >= v0.2

如何使用

  1. 为您的 FuelPHP 应用程序安装此包。转到您的 FuelPHP 应用程序包文件夹。

    cd your_fuel_app/fuel/packages/
    git clone git://github.com/andreoav/fuel-opauth.git opauth
  2. 将位于 PKGPATH/opauth/config/opauth.php 的 opauth 配置文件复制到您的_fuel_app/fuel/app/config/,更改安全盐并根据需要调整。例如。

    <?php
    'path' => '/auth/login/',
    'callback_url' => '/auth/callback/',
    'Strategy' => array(
    	'Facebook' => array(
    		'app_id' => 'APP_ID',
    		'app_secret' => 'APP_SECRET'
    	),
    ),
  3. 启用 fuel-opauth 包。

    <?php
    'always_load' => array(
    	'packages' => array(
    		'opauth',
    	),
    ),
  4. 创建一个名为 Controller_Auth 的控制器和一个名为 login 的动作。例如。

    <?php
    class Controller_Auth extends Controller
    {
    	private $_config = null;
    
    	public function before()
    	{
    		if(!isset($this->_config))
    		{
    			$this->_config = Config::load('opauth', 'opauth');
    		}
    	}
    	
    	/**
    	 * eg. http://www.exemple.org/auth/login/facebook/ will call the facebook opauth strategy.
    	 * Check if $provider is a supported strategy.
    	 */
    	public function action_login($_provider = null)
    	{
    		if(array_key_exists(Inflector::humanize($_provider), Arr::get($this->_config, 'Strategy')))
    		{
    			$_oauth = new Opauth($this->_config, true);
    		}
    		else
    		{
    			return Response::forge('Strategy not supported');
    		}
    	}
    	
    	// Print the user credentials after the authentication. Use this information as you need. (Log in, registrer, ...)
    	public function action_callback()
    	{
    		$_opauth = new Opauth($this->_config, false);
    		
    		switch($_opauth->env['callback_transport'])
    		{
    			case 'session':
    				session_start();
    				$response = $_SESSION['opauth'];
    				unset($_SESSION['opauth']);
    			break;            
    		}
    		
    		if (array_key_exists('error', $response))
    		{
    			echo '<strong style="color: red;">Authentication error: </strong> Opauth returns error auth response.'."<br>\n";
    		}
    		else
    		{
    			if (empty($response['auth']) || empty($response['timestamp']) || empty($response['signature']) || empty($response['auth']['provider']) || empty($response['auth']['uid']))
    			{
    				echo '<strong style="color: red;">Invalid auth response: </strong>Missing key auth response components.'."<br>\n";
    			}
    			elseif (!$_opauth->validate(sha1(print_r($response['auth'], true)), $response['timestamp'], $response['signature'], $reason))
    			{
    				echo '<strong style="color: red;">Invalid auth response: </strong>'.$reason.".<br>\n";
    			}
    			else
    			{
    				echo '<strong style="color: green;">OK: </strong>Auth response is validated.'."<br>\n";
    		
    				/**
    				 * It's all good. Go ahead with your application-specific authentication logic
    				 */
    			}
    		}
    		
    		return Response::forge(var_dump($response));
    	}
    }

可用的策略

策略是一组与相应的身份验证提供商接口并将其回传给 Opauth 的指令集。本包包含 Facebook 和 Twitter 的策略。要安装其他策略,请将文件复制到 PKGPATH/opauth/classes/ 文件夹。

特定提供商

通用策略:OAuth

有关 Opauth 策略的更新列表或请求,请参阅wiki 的策略列表。如果您想贡献策略,请参阅策略贡献指南