scharrier / li3_socialauth

此包最新版本(dev-master)没有提供许可信息。

Lithium 社交 OAuth 适配器

dev-master 2014-12-17 20:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:09:28 UTC


README

很抱歉,此 li3 包尚未得到维护。如果有人想接手,请直接联系我。

Lithium 通用的 OAuth 插件:使用 Lusitanian(https://github.com/Lusitanian/PHPoAuthLib)提供的优秀 OAuth 库来提供 Li3 认证适配器。

安装

安装 li3_socialauth 最简单的方法是使用 composer,在您的 composer.json 文件中添加以下行

{
    "require": {
        "scharrier/li3_socialauth": "dev-master"
    }
}

然后更新您的项目

composer update

并加载库

// config/bootstrap/libraries.php
Libraries::add('li3_socialauth') ;

// Add the composer autoloader if not already done
require_once(LITHIUM_LIBRARY_PATH . '/autoload.php') ;

使用 li3_socialauth

每种社交认证类型都有自己的 Lithium 认证适配器。只需像这样定义您的新认证

Auth::config(array(
  'twitter' => array(
  	'adapter' => 'Twitter',
      'key' => 'YOUR_KEY',
      'secret' => 'YOUR_SECRET'
  ),
  'facebook' => array(
    'adapter' => 'Facebook',
      'key' => 'YOUR_KEY',
      'secret' => 'YOUR_SECRET',
      'scope' => array('email','read_friendlists','user_online_presence')   // Extend the auth scope
  )
));

然后您就可以像使用其他任何 Lithium 认证机制一样使用这个认证。以下是一个 OAuth 登录方法的示例

public function login() {
    // The user choose an external auth : adapter name given as the first param
    if (!empty($this->request->params['args'][0])) {
        // Can we login in ?
		if (Auth::check($this->request->params['args'][0], $this->request)) {
			$this->redirect('/') ;
		}
	}
}

完成。

通用认证类

使用此认证方法,您将迅速拥有大量适配器以检查以获取认证用户。因此,我创建了一个通用的 Auth 类,它会在调用 check() 或 clear() 方法时检查每个适配器。

以下是一个使用示例

// Using li3_socialauth instead of Lithium auth
use li3_socialauth\extensions\security\Auth;

if (Auth::check()) {
    echo 'Logout ?' ;
} else {
    echo 'You should login first' ;
}

支持的服务

实际上这些服务都得到了支持。更多服务即将推出

  • Twitter
  • Facebook
  • Google+
  • Microsoft Live
  • Github
  • Foursquare

帮助和支持

复制它,玩弄它,提交并拉取!如有需要帮助,请发送电子邮件至 scharrier@gmail.com