Commit baee44c9 by Yuan Chong Committed by Carsten Brandt

OAuth API Response with 20x status should be in normal

Hello, I used **Yii2 authclient** to build a Github OAuth (2.0) client, and performed a POST call to create a Github repository hook. But I got this exception: ``` exception 'yii\authclient\InvalidResponseException' with message ' Request failed with code: 201, message: { "url": "https://api.github.com/repos/ychongsaytc/example/hooks/1000000", "test_url": "https://api.github.com/repos/ychongsaytc/example/hooks/1000000/test", "id": 1000000, "name": "web", "active": true, "events": ["push"], "config": { "url": "https://example.com/payload", "content_type": "form", "secret": null }, "last_response": { "code": null, "status": "unused", "message": null }, "updated_at": "2014-09-14T03:02:55Z", "created_at": "2014-09-14T03:02:55Z" } ' in /home/ubuntu/public_html/live/vendor/yiisoft/yii2-authclient/BaseOAuth.php:206 ``` I think a successful API call is not always exactly return **200** status, like **Create a hook** API of Github: https://developer.github.com/v3/repos/hooks/ It will return `201 Created` if hook was successfully created. In my opinion, is status code starts with **20** in normal scenario? close #5011
parent e6aad908
......@@ -88,7 +88,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if ($this->_returnUrl === null) {
$this->_returnUrl = $this->defaultReturnUrl();
}
return $this->_returnUrl;
}
......@@ -202,7 +201,7 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if ($errorNumber > 0) {
throw new Exception('Curl error requesting "' . $url . '": #' . $errorNumber . ' - ' . $errorMessage);
}
if ($responseHeaders['http_code'] != 200) {
if (strncmp($responseHeaders['http_code'], '20', 2) !== 0) {
throw new InvalidResponseException($responseHeaders, $response, 'Request failed with code: ' . $responseHeaders['http_code'] . ', message: ' . $response);
}
......@@ -232,7 +231,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
}
}
}
return $res;
}
......@@ -291,7 +289,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
throw new Exception('Unknown response type "' . $contentType . '".');
}
}
return $response;
}
......@@ -311,7 +308,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$result[$key] = $this->convertXmlToArray($value);
}
}
return $result;
}
......@@ -333,7 +329,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
return self::CONTENT_TYPE_XML;
}
}
return self::CONTENT_TYPE_AUTO;
}
......@@ -353,7 +348,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if (preg_match('/^<.*>$/is', $rawContent)) {
return self::CONTENT_TYPE_XML;
}
return self::CONTENT_TYPE_AUTO;
}
......@@ -367,7 +361,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if (!array_key_exists('class', $signatureMethodConfig)) {
$signatureMethodConfig['class'] = signature\HmacSha1::className();
}
return Yii::createObject($signatureMethodConfig);
}
......@@ -381,7 +374,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if (!array_key_exists('class', $tokenConfig)) {
$tokenConfig['class'] = OAuthToken::className();
}
return Yii::createObject($tokenConfig);
}
......@@ -399,7 +391,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$url .= '&';
}
$url .= http_build_query($params, '', '&', PHP_QUERY_RFC3986);
return $url;
}
......@@ -426,7 +417,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$token = $this->refreshAccessToken($token);
}
}
return $token;
}
......@@ -441,7 +431,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$session = Yii::$app->getSession();
$key = $this->getStateKeyPrefix() . $key;
$session->set($key, $value);
return $this;
}
......@@ -455,7 +444,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$session = Yii::$app->getSession();
$key = $this->getStateKeyPrefix() . $key;
$value = $session->get($key);
return $value;
}
......@@ -469,7 +457,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$session = Yii::$app->getSession();
$key = $this->getStateKeyPrefix() . $key;
$session->remove($key);
return true;
}
......@@ -502,7 +489,6 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
if (!is_object($accessToken) || !$accessToken->getIsValid()) {
throw new Exception('Invalid access token.');
}
return $this->apiInternal($accessToken, $url, $method, $params, $headers);
}
......
......@@ -6,6 +6,7 @@ Yii Framework 2 authclient extension Change Log
- Bug #3633: OpenId return URL comparison advanced to prevent url encode problem (klimov-paul)
- Bug #4490: `yii\authclient\widgets\AuthChoice` does not preserve initial settings while opening popup (klimov-paul)
- Bug #5011: OAuth API Response with 20x status were not considered success (ychongsaytc)
- Enh #3416: VKontakte OAuth support added (klimov-paul)
- Enh #4076: Request HTTP headers argument added to `yii\authclient\BaseOAuth::api()` method (klimov-paul)
- Enh #4134: `yii\authclient\InvalidResponseException` added for tracking invalid remote server response (klimov-paul)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment