Skip to content

Commit

Permalink
Merge branch 'hotfix/2.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Sep 4, 2014
2 parents b23b6d7 + 9aeec0f commit 011d65b
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 31 deletions.
12 changes: 0 additions & 12 deletions README.md
Expand Up @@ -202,18 +202,6 @@ endpoint:
),
);

> NOTE: As we are using [Guzzle](http://guzzle3.readthedocs.org/) for
> sending HTTP request, this style will NOT works if you are:
>
> - Setting `debug_endpoint` to current instance (in whatever absolute
> nor relative URL style), AND
> - The current instance is running with PHP build-in web server (in
> single thread style).
>
> The build-in web server will deadlocked, and your browser will just
> keep on waiting for timeout with
> [WSOD](http://en.wikipedia.org/wiki/Screen_of_death).
Demo
----

Expand Down
4 changes: 2 additions & 2 deletions app/config/security.php
Expand Up @@ -71,7 +71,7 @@
'resource_type' => 'debug_endpoint',
'scope' => array('demoscope1'),
'options' => array(
'debug_endpoint' => 'http://oauth2-php.authbucket.com/api/v1.0/oauth2/debug',
'debug_endpoint' => '/api/v1.0/oauth2/debug',
'cache' => false,
),
),
Expand All @@ -82,7 +82,7 @@
'resource_type' => 'debug_endpoint',
'scope' => array('demoscope1'),
'options' => array(
'debug_endpoint' => 'http://oauth2-php.authbucket.com/api/v1.0/oauth2/debug',
'debug_endpoint' => '/api/v1.0/oauth2/debug',
'cache' => true,
),
),
Expand Down
Expand Up @@ -122,6 +122,7 @@ public function register(Application $app)

$app['authbucket_oauth2.resource_handler.factory'] = $app->share(function ($app) {
return new ResourceTypeHandlerFactory(
$app,
$app['authbucket_oauth2.model_manager.factory'],
$app['authbucket_oauth2.resource_handler']
);
Expand Down
Expand Up @@ -12,6 +12,7 @@
namespace AuthBucket\OAuth2\ResourceType;

use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
* Shared resource type implementation.
Expand All @@ -20,12 +21,15 @@
*/
abstract class AbstractResourceTypeHandler implements ResourceTypeHandlerInterface
{
protected $httpKernel;
protected $modelManagerFactory;

public function __construct(
HttpKernelInterface $httpKernel,
ModelManagerFactoryInterface $modelManagerFactory
)
{
$this->httpKernel = $httpKernel;
$this->modelManagerFactory = $modelManagerFactory;
}
}
Expand Up @@ -52,13 +52,25 @@ public function handle(
}
}

// Fetch meta data of supplied access token by query remote debug endpoint.
$client = new \Guzzle\Http\Client();
$crawler = $client->get($options['debug_endpoint'], array(), array(
'headers' => array('Authorization' => implode(' ', array('Bearer', $accessToken))),
'exceptions' => false,
));
$response = json_decode($crawler->send()->getBody(), true);
// Fetch meta data of supplied access token by query debug endpoint.
if (strpos($options['debug_endpoint'], '/') === 0) {
// For relative URL, use Symfony test client to simulates and
// HTTP client like a browser and makes requests.
$client = new \Symfony\Component\HttpKernel\Client($this->httpKernel);
$crawler = $client->request('GET', $options['debug_endpoint'], array(), array(), array(
'HTTP_Authorization' => implode(' ', array('Bearer', $accessToken)),
));
$content = $client->getResponse()->getContent();
} else {
// For absolute URL, use Guzzle client to create request.
$client = new \Guzzle\Http\Client();
$crawler = $client->get($options['debug_endpoint'], array(), array(
'headers' => array('Authorization' => implode(' ', array('Bearer', $accessToken))),
'exceptions' => false,
));
$content = $crawler->send()->getBody();
}
$response = json_decode($content, true);

// Throw exception if error return.
if (isset($response['error'])) {
Expand Down
Expand Up @@ -13,6 +13,7 @@

use AuthBucket\OAuth2\Exception\ServerErrorException;
use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
* OAuth2 resource type handler factory implemention.
Expand All @@ -21,14 +22,17 @@
*/
class ResourceTypeHandlerFactory implements ResourceTypeHandlerFactoryInterface
{
protected $httpKernel;
protected $modelManagerFactory;
protected $classes;

public function __construct(
HttpKernelInterface $httpKernel,
ModelManagerFactoryInterface $modelManagerFactory,
array $classes = array()
)
{
$this->httpKernel = $httpKernel;
$this->modelManagerFactory = $modelManagerFactory;

foreach ($classes as $class) {
Expand Down Expand Up @@ -62,6 +66,7 @@ public function getResourceTypeHandler($type = null)
$class = $this->classes[$type];

return new $class(
$this->httpKernel,
$this->modelManagerFactory
);
}
Expand Down
Expand Up @@ -22,6 +22,7 @@ class ResourceTypeHandlerFactoryTest extends WebTestCase
public function testNonExistsResourceTypeHandler()
{
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(
$this->app,
$this->app['authbucket_oauth2.model_manager.factory'],
array('foo' => 'AuthBucket\\OAuth2\\Tests\\ResourceType\\NonExistsResourceTypeHandler')
);
Expand All @@ -34,6 +35,7 @@ public function testNonExistsResourceTypeHandler()
public function testBadAddResourceTypeHandler()
{
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(
$this->app,
$this->app['authbucket_oauth2.model_manager.factory'],
array('foo' => 'AuthBucket\\OAuth2\\Tests\\ResourceType\\FooResourceTypeHandler')
);
Expand All @@ -46,6 +48,7 @@ public function testBadAddResourceTypeHandler()
public function testBadGetResourceTypeHandler()
{
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(
$this->app,
$this->app['authbucket_oauth2.model_manager.factory'],
array('bar' => 'AuthBucket\\OAuth2\\Tests\\ResourceType\\BarResourceTypeHandler')
);
Expand All @@ -55,6 +58,7 @@ public function testBadGetResourceTypeHandler()
public function testGoodGetResourceTypeHandler()
{
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(
$this->app,
$this->app['authbucket_oauth2.model_manager.factory'],
array('bar' => 'AuthBucket\\OAuth2\\Tests\\ResourceType\\BarResourceTypeHandler')
);
Expand Down
Expand Up @@ -134,14 +134,6 @@ $app['security.firewalls'] = array(
),
),
);</code></pre>
<blockquote>
<p>NOTE: As we are using <a href="http://guzzle3.readthedocs.org/">Guzzle</a> for sending HTTP request, this style will NOT works if you are:</p>
<ul>
<li>Setting <code>debug_endpoint</code> to current instance (in whatever absolute nor relative URL style), AND</li>
<li>The current instance is running with PHP build-in web server (in single thread style).</li>
</ul>
<p>The build-in web server will deadlocked, and your browser will just keep on waiting for timeout with <a href="http://en.wikipedia.org/wiki/Screen_of_death">WSOD</a>.</p>
</blockquote>

<h2 id="demo" class="page-header">Demo</h2>
<p class="lead">The demo is based on <a href="http://silex.sensiolabs.org/">Silex</a> and <a href="https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php">AuthBucketOAuth2ServiceProvider</a>. Read though <a href="http://oauth2-php.authbucket.com/demo">Demo</a> for more information.</p>
Expand Down
Expand Up @@ -29,7 +29,7 @@
window.twttr=(function(j,d,i){var h,k,l=j.getElementsByTagName(d)[0];
if(j.getElementById(i)){return}k=j.createElement(d);
k.id=i;k.async=1;k.src="https://platform.twitter.com/widgets.js";
l.parentNode.insertBefore(k,l);returnwindow.twttr||(h={_e:[],ready:function(a){h._e.push(a)
l.parentNode.insertBefore(k,l);return window.twttr||(h={_e:[],ready:function(a){h._e.push(a)
}})}(document,"script","twitter-wjs"));
</script>

Expand Down
Expand Up @@ -10,4 +10,4 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/languages/php.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- holder.js -->
<script src="//cdnjs.cloudflare.com/ajax/libs/holder/2.4.0/holder.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/holder/2.3.2/holder.min.js"></script>

0 comments on commit 011d65b

Please sign in to comment.