commit
129f9c4a32
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace League\OAuth2\Client\Provider;
|
namespace League\OAuth2\Client\Provider;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
use Guzzle\Http\Exception\BadResponseException;
|
use Guzzle\Http\Exception\BadResponseException;
|
||||||
use Guzzle\Service\Client as GuzzleClient;
|
use Guzzle\Service\Client as GuzzleClient;
|
||||||
use League\OAuth2\Client\Exception\IDPException as IDPException;
|
use League\OAuth2\Client\Exception\IDPException as IDPException;
|
||||||
|
@ -34,6 +35,8 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
|
|
||||||
protected $httpClient;
|
protected $httpClient;
|
||||||
|
|
||||||
|
protected $redirectHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int This represents: PHP_QUERY_RFC1738, which is the default value for php 5.4
|
* @var int This represents: PHP_QUERY_RFC1738, which is the default value for php 5.4
|
||||||
* and the default encryption type for the http_build_query setup
|
* and the default encryption type for the http_build_query setup
|
||||||
|
@ -128,13 +131,18 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&');
|
return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
public function authorize($options = [])
|
public function authorize($options = [])
|
||||||
{
|
{
|
||||||
header('Location: '.$this->getAuthorizationUrl($options));
|
$url = $this->getAuthorizationUrl($options);
|
||||||
|
if ($this->redirectHandler) {
|
||||||
|
$handler = $this->redirectHandler;
|
||||||
|
return $handler($url);
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
header('Location: ' . $url);
|
||||||
exit;
|
exit;
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
|
|
||||||
public function getAccessToken($grant = 'authorization_code', $params = [])
|
public function getAccessToken($grant = 'authorization_code', $params = [])
|
||||||
{
|
{
|
||||||
|
@ -302,4 +310,9 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRedirectHandler(Closure $handler)
|
||||||
|
{
|
||||||
|
$this->redirectHandler = $handler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,21 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals($value, $mockProvider->{$key});
|
$this->assertEquals($value, $mockProvider->{$key});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetRedirectHandler()
|
||||||
|
{
|
||||||
|
$this->testFunction = false;
|
||||||
|
|
||||||
|
$callback = function ($url) {
|
||||||
|
$this->testFunction = $url;
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->provider->setRedirectHandler($callback);
|
||||||
|
|
||||||
|
$this->provider->authorize('http://test.url/');
|
||||||
|
|
||||||
|
$this->assertNotFalse($this->testFunction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
|
class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
|
||||||
|
|
Loading…
Reference in New Issue