adprocas/laravel-oauth2

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

使用多个OAuth 2.0提供者授权您的应用程序中的用户。

0.2.6 2013-06-25 12:20 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:25:47 UTC


README

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

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

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

通过Composer安装

将此添加到您的composer.json文件中的require对象;

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

之后,运行composer install以安装Laravel OAuth 2.0。

当前支持

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

使用示例

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