taylorotwell/laravel-oauth2

此包最新版本(0.2.6)没有可用的许可信息。

请不要再使用此包。请使用 madewithlove/laravel-oauth2 代替。

0.2.6 2013-06-25 12:20 UTC

This package is auto-updated.

Last update: 2024-09-08 00:29:46 UTC


README

这是基于Phil Sturgeon维护的CodeIgniter OAuth2 Spark开发的。

以驱动程序为基础的方式授权用户,意味着一个实现适用于多个OAuth 2服务提供商。这仅用于验证到OAuth2服务提供商,而不是构建OAuth2服务。

注意,此Spark仅提供授权机制。下面有一个示例控制器,但在后续版本中将有完整的控制器。

通过Composer安装

将以下内容添加到您的composer.json文件中的require对象中;

"taylorotwell/laravel-oauth2": "0.2.*"

然后,运行composer install来安装Laravel OAuth 2.0。

当前支持

  • Facebook
  • GitHub
  • Google
  • Windows Live
  • YouTube
  • Moves
  • Runkeeper

使用示例

http://example.com/auth/session/facebook

use OAuth2\OAuth2;
use OAuth2\Token_Access;
use OAuth2\Exception as OAuth2_Exception;

public function action_session($provider)
{
	$provider = OAuth2::provider($provider, array(
		'id' => 'your-client-id',
		'secret' => 'your-client-secret',
	));

	if ( ! isset($_GET['code']))
	{
		// By sending no options it'll come back here
		return $provider->authorize();
	}
	else
	{
		// Howzit?
		try
		{
			$params = $provider->access($_GET['code']);
			
        		$token = new Token_Access(array(
        			'access_token' => $params->access_token
        		));
        		$user = $provider->get_user_info($token);

			// Here you should use this information to A) look for a user B) help a new user sign up with existing data.
			// If you store it all in a cookie and redirect to a registration page this is crazy-simple.
			echo "<pre>";
			var_dump($user);
		}
		
		catch (OAuth2_Exception $e)
		{
			show_error('That didnt work: '.$e);
		}
	}
}