Rename OAuth\Exception back to OAuthException, to follow the standard PHP way of naming predefined / SPL exceptions.
This commit is contained in:
parent
f8be34b748
commit
d94446782a
@ -17,6 +17,6 @@ namespace GaryJones\OAuth;
|
|||||||
* @package OAuth
|
* @package OAuth
|
||||||
* @author Andy Smith
|
* @author Andy Smith
|
||||||
*/
|
*/
|
||||||
class Exception extends \Exception
|
class OAuthException extends \Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -329,7 +329,7 @@ class Request
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
public function toHeader($realm = null)
|
public function toHeader($realm = null)
|
||||||
{
|
{
|
||||||
@ -347,7 +347,7 @@ class Request
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_array($v)) {
|
if (is_array($v)) {
|
||||||
throw new Exception('Arrays not supported in headers');
|
throw new OAuthException('Arrays not supported in headers');
|
||||||
}
|
}
|
||||||
$out .= ($first) ? ' ' : ',';
|
$out .= ($first) ? ' ' : ',';
|
||||||
$out .= Util::urlencodeRfc3986($k) .
|
$out .= Util::urlencodeRfc3986($k) .
|
||||||
|
@ -149,7 +149,7 @@ class Server
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function getVersion(Request &$request)
|
private function getVersion(Request &$request)
|
||||||
{
|
{
|
||||||
@ -160,7 +160,7 @@ class Server
|
|||||||
$version = '1.0';
|
$version = '1.0';
|
||||||
}
|
}
|
||||||
if ($version !== $this->version) {
|
if ($version !== $this->version) {
|
||||||
throw new Exception("OAuth version '$version' not supported");
|
throw new OAuthException("OAuth version '$version' not supported");
|
||||||
}
|
}
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ class Server
|
|||||||
*
|
*
|
||||||
* @return string Signature method name.
|
* @return string Signature method name.
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function getSignatureMethod(Request $request)
|
private function getSignatureMethod(Request $request)
|
||||||
{
|
{
|
||||||
@ -181,11 +181,11 @@ class Server
|
|||||||
if (!$signature_method) {
|
if (!$signature_method) {
|
||||||
// According to chapter 7 ("Accessing Protected Resources") the signature-method
|
// According to chapter 7 ("Accessing Protected Resources") the signature-method
|
||||||
// parameter is required, and we can't just fallback to PLAINTEXT
|
// parameter is required, and we can't just fallback to PLAINTEXT
|
||||||
throw new Exception('No signature method parameter. This parameter is required');
|
throw new OAuthException('No signature method parameter. This parameter is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($signature_method, array_keys($this->signature_methods))) {
|
if (!in_array($signature_method, array_keys($this->signature_methods))) {
|
||||||
throw new Exception(
|
throw new OAuthException(
|
||||||
"Signature method '$signature_method' not supported, try one of the following: " .
|
"Signature method '$signature_method' not supported, try one of the following: " .
|
||||||
implode(", ", array_keys($this->signature_methods))
|
implode(", ", array_keys($this->signature_methods))
|
||||||
);
|
);
|
||||||
@ -200,19 +200,19 @@ class Server
|
|||||||
*
|
*
|
||||||
* @return GaryJones\OAuth\Client
|
* @return GaryJones\OAuth\Client
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function getClient(Request $request)
|
private function getClient(Request $request)
|
||||||
{
|
{
|
||||||
$client_key = $request instanceof Request ? $request->getParameter('oauth_consumer_key') : null;
|
$client_key = $request instanceof Request ? $request->getParameter('oauth_consumer_key') : null;
|
||||||
|
|
||||||
if (!$client_key) {
|
if (!$client_key) {
|
||||||
throw new Exception('Invalid client key');
|
throw new OAuthException('Invalid client key');
|
||||||
}
|
}
|
||||||
|
|
||||||
$client = $this->data_store->lookupClient($client_key);
|
$client = $this->data_store->lookupClient($client_key);
|
||||||
if (!$client) {
|
if (!$client) {
|
||||||
throw new Exception('Invalid client');
|
throw new OAuthException('Invalid client');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
@ -227,7 +227,7 @@ class Server
|
|||||||
*
|
*
|
||||||
* @return GaryJones\OAuth\Token
|
* @return GaryJones\OAuth\Token
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function getToken(Request $request, Client $client, $token_type = 'access')
|
private function getToken(Request $request, Client $client, $token_type = 'access')
|
||||||
{
|
{
|
||||||
@ -235,7 +235,7 @@ class Server
|
|||||||
|
|
||||||
$token = $this->data_store->lookupToken($client, $token_type, $token_field);
|
$token = $this->data_store->lookupToken($client, $token_type, $token_field);
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
throw new Exception("Invalid $token_type token: $token_field");
|
throw new OAuthException("Invalid $token_type token: $token_field");
|
||||||
}
|
}
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ class Server
|
|||||||
* @param GaryJones\OAuth\Client $client
|
* @param GaryJones\OAuth\Client $client
|
||||||
* @param GaryJones\OAuth\Token $token
|
* @param GaryJones\OAuth\Token $token
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function checkSignature(Request $request, Client $client, Token $token)
|
private function checkSignature(Request $request, Client $client, Token $token)
|
||||||
{
|
{
|
||||||
@ -266,7 +266,7 @@ class Server
|
|||||||
$valid_sig = $signature_method->checkSignature($request, $client, $token, $signature);
|
$valid_sig = $signature_method->checkSignature($request, $client, $token, $signature);
|
||||||
|
|
||||||
if (!$valid_sig) {
|
if (!$valid_sig) {
|
||||||
throw new Exception('Invalid signature');
|
throw new OAuthException('Invalid signature');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,18 +275,18 @@ class Server
|
|||||||
*
|
*
|
||||||
* @param int $timestamp
|
* @param int $timestamp
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function checkTimestamp($timestamp)
|
private function checkTimestamp($timestamp)
|
||||||
{
|
{
|
||||||
if (!$timestamp) {
|
if (!$timestamp) {
|
||||||
throw new Exception('Missing timestamp parameter. The parameter is required');
|
throw new OAuthException('Missing timestamp parameter. The parameter is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that timestamp is recentish
|
// verify that timestamp is recentish
|
||||||
$now = time();
|
$now = time();
|
||||||
if (abs($now - $timestamp) > $this->timestamp_threshold) {
|
if (abs($now - $timestamp) > $this->timestamp_threshold) {
|
||||||
throw new Exception("Expired timestamp, yours $timestamp, ours $now");
|
throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,18 +298,18 @@ class Server
|
|||||||
* @param string $nonce
|
* @param string $nonce
|
||||||
* @param int $timestamp
|
* @param int $timestamp
|
||||||
*
|
*
|
||||||
* @throws GaryJones\OAuth\Exception
|
* @throws GaryJones\OAuth\OAuthException
|
||||||
*/
|
*/
|
||||||
private function checkNonce(Client $client, Token $token, $nonce, $timestamp)
|
private function checkNonce(Client $client, Token $token, $nonce, $timestamp)
|
||||||
{
|
{
|
||||||
if (!$nonce) {
|
if (!$nonce) {
|
||||||
throw new Exception('Missing nonce parameter. The parameter is required');
|
throw new OAuthException('Missing nonce parameter. The parameter is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that the nonce is uniqueish
|
// verify that the nonce is uniqueish
|
||||||
$found = $this->data_store->lookupNonce($client, $token, $nonce, $timestamp);
|
$found = $this->data_store->lookupNonce($client, $token, $nonce, $timestamp);
|
||||||
if ($found) {
|
if ($found) {
|
||||||
throw new Exception('Nonce already used: ' . $nonce);
|
throw new OAuthException('Nonce already used: ' . $nonce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user