[
  {
    "path": ".gitignore",
    "content": "/vendor\ncomposer.phar\ncomposer.lock\n.DS_Store"
  },
  {
    "path": "README.md",
    "content": "# OAuth wrapper for Laravel 4\n\noauth-4-laravel is a simple laravel 4 service provider (wrapper) for [Lusitanian/PHPoAuthLib](https://github.com/Lusitanian/PHPoAuthLib) \nwhich provides oAuth support in PHP 5.3+ and is very easy to integrate with any project which requires an oAuth client.\n\n---\n \n- [Supported services](#supported-services)\n- [Installation](#installation)\n- [Registering the Package](#registering-the-package)\n- [Configuration](#configuration)\n- [Usage](#usage)\n- [Basic usage](#basic-usage)\n- [More usage examples](#more-usage-examples)\n\n## Supported services\n\nThe library supports both oAuth 1.x and oAuth 2.0 compliant services. A list of currently implemented services can be found below. More services will be implemented soon.\n\nIncluded service implementations:\n\n - OAuth1\n    - BitBucket\n    - Etsy\n    - FitBit\n    - Flickr\n    - Scoop.it!\n    - Tumblr\n    - Twitter\n    - Xing\n    - Yahoo\n - OAuth2\n    - Amazon\n    - BitLy\n    - Box\n    - Dailymotion\n    - Dropbox\n    - Facebook\n    - Foursquare\n    - GitHub\n    - Google\n    - Harvest\n    - Heroku\n    - Instagram\n    - LinkedIn\n    - Mailchimp\n    - Microsoft\n    - PayPal\n    - Pocket\n    - Reddit\n    - RunKeeper\n    - SoundCloud\n    - Vkontakte\n    - Yammer\n- more to come!\n\nTo learn more about Lusitanian/PHPoAuthLib go [here](https://github.com/Lusitanian/PHPoAuthLib) \n\n## Installation\n\nUse [composer](http://getcomposer.org) to install this package.\n\n```\n$ composer require artdarek/oauth-4-laravel:dev-master\n```\n\n### Registering the Package\n\nRegister the service provider within the ```providers``` array found in ```app/config/app.php```:\n\n```php\n'providers' => array(\n\t// ...\n\t\n\t'Artdarek\\OAuth\\OAuthServiceProvider'\n)\n```\n\nAdd an alias within the ```aliases``` array found in ```app/config/app.php```:\n\n\n```php\n'aliases' => array(\n\t// ...\n\t\n\t'OAuth' => 'Artdarek\\OAuth\\Facade\\OAuth',\n)\n```\n\n## Configuration\n\nThere are two ways to configure oauth-4-laravel.\nYou can choose the most convenient way for you. \nYou can use package config file which can be \ngenerated through command line by artisan (option 1) or \nyou can simply create a config file called ``oauth-4-laravel.php`` in \nyour ``app\\config\\`` directory (option 2).\n\n#### Option 1\n\nCreate configuration file for package using artisan command\n\n```\n$ php artisan config:publish artdarek/oauth-4-laravel\n```\n\n#### Option 2\n\nCreate configuration file manually in config directory ``app/config/oauth-4-laravel.php`` and put there code from below.\n\n```php\n<?php\nreturn array( \n\t\n\t/*\n\t|--------------------------------------------------------------------------\n\t| oAuth Config\n\t|--------------------------------------------------------------------------\n\t*/\n\n\t/**\n\t * Storage\n\t */\n\t'storage' => 'Session', \n\n\t/**\n\t * Consumers\n\t */\n\t'consumers' => array(\n\n\t\t/**\n\t\t * Facebook\n\t\t */\n\t\t'Facebook' => array(\n\t\t    'client_id'     => '',\n\t\t    'client_secret' => '',\n\t\t    'scope'         => array(),\n\t\t),\t\t\n\n\t)\n\n);\n```\n\n### Credentials\n\nAdd your credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php`` or ``app/config/oauth-4-laravel.php`` (depending on which option of configuration you choose)\n\n\nThe `Storage` attribute is optional and defaults to `Session`. \nOther [options](https://github.com/Lusitanian/PHPoAuthLib/tree/master/src/OAuth/Common/Storage).\n\n## Usage\n\n### Basic usage\n\nJust follow the steps below and you will be able to get a [service class object](https://github.com/Lusitanian/PHPoAuthLib/tree/master/src/OAuth/OAuth2/Service) with this one rule:\n\n```php\n$fb = OAuth::consumer('Facebook');\n```\n\nOptionally, add a second parameter with the URL which the service needs to redirect to, otherwise it will redirect to the current URL.\n\n```php\n$fb = OAuth::consumer('Facebook','http://url.to.redirect.to');\n```\n\n## Usage examples\n\n### Facebook:\n\nConfiguration:\nAdd your Facebook credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php``\n\n```php\n'Facebook' => array(\n    'client_id'     => 'Your Facebook client ID',\n    'client_secret' => 'Your Facebook Client Secret',\n    'scope'         => array('email','read_friendlists','user_online_presence'),\n),\t\n```\nIn your Controller use the following code:\n\n```php\n/**\n * Login user with facebook\n *\n * @return void\n */\n\npublic function loginWithFacebook() {\n\t\n\t// get data from input\n\t$code = Input::get( 'code' );\n\t\n\t// get fb service\n\t$fb = OAuth::consumer( 'Facebook' );\n\t\n\t// check if code is valid\n\t\n\t// if code is provided get user data and sign in\n\tif ( !empty( $code ) ) {\n\t\t\n\t\t// This was a callback request from facebook, get the token\n\t\t$token = $fb->requestAccessToken( $code );\n\t\t\n\t\t// Send a request with it\n\t\t$result = json_decode( $fb->request( '/me' ), true );\n\t\t\n\t\t$message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];\n\t\techo $message. \"<br/>\";\n\t\t\n\t\t//Var_dump\n\t\t//display whole array().\n\t\tdd($result);\n\t\n\t}\n\t// if not ask for permission first\n\telse {\n\t\t// get fb authorization\n\t\t$url = $fb->getAuthorizationUri();\n\t\t\n\t\t// return to facebook login url\n\t\t return Redirect::to( (string)$url );\n\t}\n\n}\n```\n### Google:\n\nConfiguration:\nAdd your Google credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php``\n\n```php\n'Google' => array(\n    'client_id'     => 'Your Google client ID',\n    'client_secret' => 'Your Google Client Secret',\n    'scope'         => array('userinfo_email', 'userinfo_profile'),\n),\t\n```\nIn your Controller use the following code:\n\n```php\npublic function loginWithGoogle() {\n\n\t// get data from input\n\t$code = Input::get( 'code' );\n\t\n\t// get google service\n\t$googleService = OAuth::consumer( 'Google' );\n\t\n\t// check if code is valid\n\t\n\t// if code is provided get user data and sign in\n\tif ( !empty( $code ) ) {\n\t\n\t\t// This was a callback request from google, get the token\n\t\t$token = $googleService->requestAccessToken( $code );\n\t\t\n\t\t// Send a request with it\n\t\t$result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );\n\t\t\n\t\t$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];\n\t\techo $message. \"<br/>\";\n\t\t\n\t\t//Var_dump\n\t\t//display whole array().\n\t\tdd($result);\n\t        \n\t}\n\t// if not ask for permission first\n\telse {\n\t\t// get googleService authorization\n\t\t$url = $googleService->getAuthorizationUri();\n\t\t\n\t\t// return to google login url\n\t\treturn Redirect::to( (string)$url );\n\t}\n}\n```\n\n\n### Twitter:\n\nConfiguration:\nAdd your Twitter credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php``\n\n```php\n'Twitter' => array(\n    'client_id'     => 'Your Twitter client ID',\n    'client_secret' => 'Your Twitter Client Secret',\n    // No scope - oauth1 doesn't need scope\n),\t\n```\nIn your Controller use the following code:\n\n```php\npublic function loginWithTwitter() {\n\n\t// get data from input\n\t$token = Input::get( 'oauth_token' );\n\t$verify = Input::get( 'oauth_verifier' );\n\t\n\t// get twitter service\n\t$tw = OAuth::consumer( 'Twitter' );\n\t\n\t// check if code is valid\n\t\n\t// if code is provided get user data and sign in\n\tif ( !empty( $token ) && !empty( $verify ) ) {\n\t\n\t\t// This was a callback request from twitter, get the token\n\t\t$token = $tw->requestAccessToken( $token, $verify );\n\t\t\n\t\t// Send a request with it\n\t\t$result = json_decode( $tw->request( 'account/verify_credentials.json' ), true );\n\t\t\n\t\t$message = 'Your unique Twitter user id is: ' . $result['id'] . ' and your name is ' . $result['name'];\n\t\techo $message. \"<br/>\";\n\t\t\n\t\t//Var_dump\n\t\t//display whole array().\n\t\tdd($result);\n\t        \n\t}\n\t// if not ask for permission first\n\telse {\n\t\t// get request token\n\t\t$reqToken = $tw->requestRequestToken();\n\t\t\n\t\t// get Authorization Uri sending the request token\n\t\t$url = $tw->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));\n\n\t\t// return to twitter login url\n\t\treturn Redirect::to( (string)$url );\n\t}\n}\n```\n\n\n\n### Linkedin:\n\nConfiguration:\nAdd your Linkedin credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php``\n\n```php\n'Linkedin' => array(\n    'client_id'     => 'Your Linkedin API ID',\n    'client_secret' => 'Your Linkedin API Secret',\n),\t\n```\nIn your Controller use the following code:\n\n```php\n\n public function loginWithLinkedin() {\n\n        // get data from input\n        $code = Input::get( 'code' );\n\n        $linkedinService = OAuth::consumer( 'Linkedin' );\n\n\n        if ( !empty( $code ) ) {\n\n            // This was a callback request from linkedin, get the token\n            $token = $linkedinService->requestAccessToken( $code );\n            // Send a request with it. Please note that XML is the default format.\n            $result = json_decode($linkedinService->request('/people/~?format=json'), true);\n\n            // Show some of the resultant data\n            echo 'Your linkedin first name is ' . $result['firstName'] . ' and your last name is ' . $result['lastName'];\n\n\n            //Var_dump\n            //display whole array().\n            dd($result);\n\n        }// if not ask for permission first\n        else {\n            // get linkedinService authorization\n            $url = $linkedinService->getAuthorizationUri(array('state'=>'DCEEFWF45453sdffef424'));\n\n            // return to linkedin login url\n            return Redirect::to( (string)$url );\n        }\n\n\n    }\n\n```\n### Yahoo:\n\nConfiguration:\nAdd your Yahoo credentials to ``app/config/packages/artdarek/oauth-4-laravel/config.php``\n\n```php\n'Yahoo' => array(\n            'client_id'     => 'Your Yahoo API KEY',\n            'client_secret' => 'Your Yahoo API Secret',  \n),\t\n```\nIn your Controller use the following code:\n\n```php\n\npublic function loginWithYahoo() {\n   // get data from input\n   \t$token = Input::get( 'oauth_token' );\n    $verify = Input::get( 'oauth_verifier' );\n    // get yahoo service\n    $yh = OAuth::consumer( 'Yahoo' );\n\n    // if code is provided get user data and sign in\n    if ( !empty( $token ) && !empty( $verify ) ) {\n\t\t\t\t// This was a callback request from yahoo, get the token\n\t\t\t\t$token = $yh->requestAccessToken( $token, $verify );\n\t\t\t\t$xid = array($token->getExtraParams());\n\t\t\t\t$result = json_decode( $yh->request( 'https://social.yahooapis.com/v1/user/'.$xid[0]['xoauth_yahoo_guid'].'/profile?format=json' ), true );\t\n                \n                dd($result);\t\t\t\t\t\t\t\t\n    }\n    // if not ask for permission first\n    else {\n        // get request token\n        $reqToken = $yh->requestRequestToken();\n        // get Authorization Uri sending the request token\n        $url = $yh->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));\n        // return to yahoo login url\n        return Redirect::to( (string)$url );\n    }\n}\n\n```\n### More usage examples:\n\nFor examples go [here](https://github.com/Lusitanian/PHPoAuthLib/tree/master/examples)\n\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"artdarek/oauth-4-laravel\",\n    \"type\": \"library\",\n    \"description\": \"OAuth Service Provider for Laravel 4\",\n    \"keywords\": [\"OAuth\", \"Lusitanian\", \"laravel\", \"php\"],\n    \"homepage\": \"https://github.com/artdarek/oauth-4-laravel\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Artdarek\",\n            \"email\": \"artdarek@gmail.com\",\n            \"role\": \"Developer\"\n        },\n        {\n            \"name\": \"Alejandro Escobedo\",\n            \"email\": \"aeg0204@gmail.com\",\n            \"role\": \"Developer\"\n        }\n    ],\n    \"require\": {\n        \"php\": \">=5.3\",\n        \"lusitanian/oauth\": \"dev-master\"\n    },\n    \"require-dev\": {\n        \"illuminate/support\": \"~4\"\n    },\n    \"require-all\": true,\n    \"autoload\": {\n        \"psr-0\": {\n            \"Artdarek\\\\OAuth\": \"src/\"\n        }\n    },\n    \"minimum-stability\": \"dev\"\n}\n"
  },
  {
    "path": "src/Artdarek/OAuth/Facade/OAuth.php",
    "content": "<?php \n/**\n * @author     Dariusz Prząda <artdarek@gmail.com>\n * @copyright  Copyright (c) 2013\n * @license    http://www.opensource.org/licenses/mit-license.html MIT License\n */\n\nnamespace Artdarek\\OAuth\\Facade;\n\nuse Illuminate\\Support\\Facades\\Facade;\n\nclass OAuth extends Facade \n{\n\n    /**\n     * Get the registered name of the component.\n     *\n     * @return string\n     */\n    protected static function getFacadeAccessor() { return 'oauth'; }\n\n}"
  },
  {
    "path": "src/Artdarek/OAuth/OAuth.php",
    "content": "<?php\n/**\n * @author     Dariusz Prząda <artdarek@gmail.com>\n * @copyright  Copyright (c) 2013\n * @license    http://www.opensource.org/licenses/mit-license.html MIT License\n */\n\nnamespace Artdarek\\OAuth;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nuse \\Config;\nuse \\URL;\n\nuse \\OAuth\\ServiceFactory;\nuse \\OAuth\\Common\\Consumer\\Credentials;\n\nclass OAuth\n{\n    /**\n     * @var ServiceFactory\n     */\n    private $_serviceFactory;\n\n    /**\n     * Storege name from config\n     * @var string\n     */\n    private $_storage_name = 'Session';\n\n    /**\n     * Client ID from config\n     * @var string\n     */\n    private $_client_id;\n\n    /**\n     * Client secret from config\n     * @var string\n     */\n    private $_client_secret;\n\n    /**\n     * Scope from config\n     * @var array\n     */\n    private $_scope = array();\n\n    /**\n     * Constructor\n     *\n     * @param ServiceFactory $serviceFactory - (Dependency injection) If not provided, a ServiceFactory instance will be constructed.\n     */\n    public function __construct(ServiceFactory $serviceFactory = null)\n    {\n        if (null === $serviceFactory) {\n            // Create the service factory\n            $serviceFactory = new ServiceFactory();\n        }\n        $this->_serviceFactory = $serviceFactory;\n    }\n\n    /**\n     * Detect config and set data from it\n     *\n     * @param string $service\n     */\n    public function setConfig( $service )\n    {\n        // if config/oauth-4-laravel.php exists use this one\n        if ( Config::get('oauth-4-laravel.consumers') != null ) {\n\n            $this->_storage_name = Config::get('oauth-4-laravel.storage', 'Session');\n            $this->_client_id = Config::get(\"oauth-4-laravel.consumers.$service.client_id\");\n            $this->_client_secret = Config::get(\"oauth-4-laravel.consumers.$service.client_secret\");\n            $this->_scope = Config::get(\"oauth-4-laravel.consumers.$service.scope\", array() );\n\n        // esle try to find config in packages configs\n        } else {\n            $this->_storage_name = Config::get('oauth-4-laravel::storage', 'Session');\n            $this->_client_id = Config::get(\"oauth-4-laravel::consumers.$service.client_id\");\n            $this->_client_secret = Config::get(\"oauth-4-laravel::consumers.$service.client_secret\");\n            $this->_scope = Config::get(\"oauth-4-laravel::consumers.$service.scope\", array() );\n        }\n    }\n\n    /**\n     * Create storage instance\n     *\n     * @param string $storageName\n     * @return OAuth\\Common\\\\Storage\n     */\n    public function createStorageInstance($storageName)\n    {\n        $storageClass = \"\\\\OAuth\\\\Common\\\\Storage\\\\$storageName\";\n        $storage = new $storageClass();\n\n        return $storage;\n    }\n\n    /**\n     * Set the http client object\n     *\n     * @param string $httpClientName\n     * @return void\n     */\n    public function setHttpClient($httpClientName)\n    {\n        $httpClientClass = \"\\\\OAuth\\\\Common\\\\Http\\\\Client\\\\$httpClientName\";\n        $this->_serviceFactory->setHttpClient(new $httpClientClass());\n    }\n\n    /**\n     * @param  string $service\n     * @param  string $url\n     * @param  array  $scope\n     * @return \\OAuth\\Common\\Service\\AbstractService\n     */\n    public function consumer( $service, $url = null, $scope = null )\n    {\n        // get config\n        $this->setConfig( $service );\n\n        // get storage object\n        $storage = $this->createStorageInstance( $this->_storage_name );\n\n        // create credentials object\n        $credentials = new Credentials(\n            $this->_client_id,\n            $this->_client_secret,\n            $url ?: URL::current()\n        );\n\n        // check if scopes were provided\n        if (is_null($scope))\n        {\n            // get scope from config (default to empty array)\n            $scope = $this->_scope;\n        }\n\n        // return the service consumer object\n        return $this->_serviceFactory->createService($service, $credentials, $storage, $scope);\n\n    }\n}\n"
  },
  {
    "path": "src/Artdarek/OAuth/OAuthServiceProvider.php",
    "content": "<?php \n/**\n * @author     Dariusz Prząda <artdarek@gmail.com>\n * @copyright  Copyright (c) 2013\n * @license    http://www.opensource.org/licenses/mit-license.html MIT License\n */\n\nnamespace Artdarek\\OAuth;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass OAuthServiceProvider extends ServiceProvider \n{\n\n    /**\n     * Indicates if loading of the provider is deferred.\n     *\n     * @var bool\n     */\n    protected $defer = false;\n\n    /**\n     * Bootstrap the application events.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        $this->package('artdarek/oauth-4-laravel');\n    }\n\n    /**\n     * Register the service provider.\n     *\n     * @return void\n     */\n    public function register()\n    {\n\t    // Register 'oauth'\n\t\t    $this->app['oauth'] = $this->app->share(function($app)\n\t\t    {\n                // create oAuth instance\n                \t$oauth = new OAuth();\n        \t\t// return oAuth instance\n\t\t        \treturn $oauth;\n\t\t    });\n    }\n\n    /**\n     * Get the services provided by the provider.\n     *\n     * @return array\n     */\n    public function provides()\n    {\n        return array();\n    }\n\n}"
  },
  {
    "path": "src/config/.gitkeep",
    "content": ""
  },
  {
    "path": "src/config/config.php",
    "content": "<?php \n\nreturn array( \n\t\n\t/*\n\t|--------------------------------------------------------------------------\n\t| oAuth Config\n\t|--------------------------------------------------------------------------\n\t*/\n\n\t/**\n\t * Storage\n\t */\n\t'storage' => 'Session', \n\n\t/**\n\t * Consumers\n\t */\n\t'consumers' => array(\n\n\t\t/**\n\t\t * Facebook\n\t\t */\n        'Facebook' => array(\n            'client_id'     => '',\n            'client_secret' => '',\n            'scope'         => array(),\n        ),\t\t\n\n\t)\n\n);"
  }
]