madewithlove / laravel-oauth2
0.4.13
2015-03-29 11:59 UTC
Requires
README
⚠️ 此包已弃用
请使用 Laravel Socialite 进行OAuth登录,而不是使用此过时的包。
这是Talor Otwell的Laravel-oAuth2包的Laravel 4版本移植。它基于Phil Sturgeon维护的CodeIgniter OAuth2 Spark。
以驱动程序为基础的方式授权您的应用程序中的用户,意味着一个实现可以适用于多个OAuth 2提供商。这只是为了认证到OAuth 2提供商,而不是构建OAuth 2服务。
注意,此包仅提供授权机制。以下是一个示例控制器。
通过Composer安装
将此添加到您的composer.json文件中的require对象;
"madewithlove/laravel-oauth2": "0.4.*"
之后,运行composer install来安装Laravel OAuth 2.0。
当前支持
- Foursquare
- GitHub
- iHealth
- Jawbone
- Mailchimp
- Misfit
- Moves
- Runkeeper
- Strava
- Uber
- Under Armour
- Windows Live
- YouTube
使用示例
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); } } }