dscafati / laravel-oauth2
此包的最新版本(0.4.14)没有可用的许可信息。
使用多个 OAuth 2.0 提供商在您的应用程序中授权用户。
0.4.14
2016-01-19 02:01 UTC
Requires
- laravel/framework: 5.0.*
README
这是 Talor Otwell 的 Laravel-oAuth2 套件到 Laravel 4 的移植版。它基于 Phil Sturgeon 维护的 CodeIgniter OAuth2 Spark。
以驱动程序为基础的方式授权您的应用程序中的用户,意味着一个实现适用于多个 OAuth 2 提供商。这仅用于对 OAuth2 提供商进行身份验证,而不是构建 OAuth2 服务。
请注意,此包 仅 提供授权机制。下面有一个示例控制器。
通过 Composer 安装
将以下内容添加到您的 composer.json 文件中的 require 对象:
"SimpleUsername/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); } } }