定制 uzura8/fuel-packages-opauth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uzura8/fuel-packages-opauth

Composer 安装命令:

composer require uzura8/fuel-packages-opauth

包简介

README 文档

README

FuelPHP package for Opauth

FuelPHP 1.x package for Opauth.

Opauth is a multi-provider authentication framework.

Requirements

FuelPHP v1.x
Opauth >= v0.2

How to use

  1. Install this package for your FuelPHP application. Go to your FuelPHP application package folder.

    cd your_fuel_app/fuel/packages/
    git clone git://github.com/andreoav/fuel-opauth.git opauth
  2. Copy the opauth configuration file located at PKGPATH/opauth/config/opauth.php to your_fuel_app/fuel/app/config/, change the security salt and tweak as you need. eg.

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

    <?php
    'always_load' => array(
    	'packages' => array(
    		'opauth',
    	),
    ),
  4. Create a controller called Controller_Auth and an action called login. eg.

    <?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));
    	}
    }

Available strategies

A strategy is a set of instructions that interfaces with respective authentication providers and relays it back to Opauth. This package comes with strategies for Facebook and twitter. To install other strategies copy the files to PKGPATH/opauth/classes/Strategy/ folder.

Provider-specific:

Strategy Maintained by
Facebook   Facebook uzyn
Google   Google uzyn
Instagram   Instagram muhdazrain
LinkedIn   LinkedIn uzyn
mixi   mixi ritou
OpenID   OpenID uzyn
Twitter   Twitter uzyn

Generic strategy: OAuth

See wiki's list of strategies for an updated list of Opauth strategies or to make requests. Also, refer to strategy contribution guide if you would like to contribute a strategy.

统计信息

  • 总下载量: 343
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-02