Skip to content

Commit

Permalink
Small fixes/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariusz Prząda committed Nov 19, 2013
1 parent 5c9f588 commit 397621b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
89 changes: 55 additions & 34 deletions src/Artdarek/OAuth/OAuth.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
<?php namespace Artdarek\OAuth;

/*
|--------------------------------------------------------------------------
| How to use
|--------------------------------------------------------------------------
| eg:
|
| $fb = OAuth::consumer('Facebook');
|
| returns a configured consumer object
| class details found here:
| https://github.com/Lusitanian/PHPoAuthLib/blob/master/src/OAuth/OAuth2/Service/Facebook.php
|
| credentials and scope are loaded from config/oauth.php
|
*/
<?php
/**
* @author Dariusz Prząda <artdarek@gmail.com>
* @copyright Copyright (c) 2013
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/

use Illuminate\Support\ServiceProvider;
namespace Artdarek\OAuth;

use \OAuth\ServiceFactory;
use \OAuth\Common\Consumer\Credentials;
use Illuminate\Support\ServiceProvider;

use \Config;
use \URL;

class OAuth {
use \OAuth\ServiceFactory;
use \OAuth\Common\Consumer\Credentials;

class OAuth
{
/**
* @param string $service
* @return \OAuth\Common\Service\AbstractService
* @var ServiceFactory
*/
private $serviceFactory;

/**
* Constructor
*/
public function consumer( $service, $url = null ) {
public function __construct() {

// create a service factory
$this->serviceFactory = new ServiceFactory();

}

// create a factory. but remember: this is not java.
$service_factory = new ServiceFactory();
/**
* Create storage instance
*
* @param string $storageName
* @return OAuth\Common\\Storage
*/
public createStorageInstance($storageName)
{
$storageClass = "\\OAuth\Common\\Storage\\$storage_name";
$storage = new $storageClass();

// get storage
$storage_name = Config::get('oauth-4-laravel::storage') ?: 'Session'; // default
return $storage;
}

$cn = "\\OAuth\Common\\Storage\\$storage_name";
$storage = new $cn();
/**
* @param string $service
* @param string $url
* @param array $scope
* @return \OAuth\Common\Service\AbstractService
*/
public function consumer( $service, $url = null, $scope = null )
{
// get storage object
$storage_name = Config::get('oauth-4-laravel::storage', 'Session');
$storage = createStorageInstance( $storage_name );

// create credentials object
$credentials = new Credentials(
Expand All @@ -48,11 +65,15 @@ public function consumer( $service, $url = null ) {
$url ?: URL::current()
);

// get scope (default to empty array)
$scope = Config::get("oauth-4-laravel::consumers.$service.scope") ?: array();
// check if scopes were provided
if (is_null($scope))
{
// get scope from config (default to empty array)
$scope = Config::get("oauth-4-laravel::consumers.$service.scope", array() );
}

// return the service consumer object
return $service_factory->createService($service, $credentials, $storage, $scope);
return $this->serviceFactory->createService($service, $credentials, $storage, $scope);

}
}
}
10 changes: 5 additions & 5 deletions src/Artdarek/OAuth/OAuthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php namespace Artdarek\OAuth;
<?php

namespace Artdarek\OAuth;

use Illuminate\Support\ServiceProvider;

class OAuthServiceProvider extends ServiceProvider {
class OAuthServiceProvider extends ServiceProvider
{

/**
* Indicates if loading of the provider is deferred.
Expand Down Expand Up @@ -31,13 +34,10 @@ public function register()
// Register 'oauth'
$this->app['oauth'] = $this->app->share(function($app)
{

// create oAuth instance
$oauth = new OAuth();

// return oAuth instance
return $oauth;

});
}

Expand Down

0 comments on commit 397621b

Please sign in to comment.