Skip to content

Commit 3c65842

Browse files
committed
Fix BC break in yii2-httpclient - Request::getUrl() returns URL without data.
1 parent 770a982 commit 3c65842

File tree

4 files changed

+78
-49
lines changed

4 files changed

+78
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
1.0.1 (under development)
66
-------------------------
77

8-
- No changes have been made.
8+
- Fix BC break in `yii2-httpclient` - `Request::getUrl()` returns URL without data.
99

1010

1111
1.0.0 (2016-09-04)

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"source": "https://github.com/rob006/yii2-simple-auth-yii-authenticator"
1717
},
1818
"require": {
19-
"yiisoft/yii2": "2.0.*",
20-
"yiisoft/yii2-httpclient": "2.0.*",
19+
"yiisoft/yii2": "~2.0.9",
20+
"yiisoft/yii2-httpclient": "~2.0.1",
2121
"rob006/yii2-simple-auth": "^1.0"
2222
},
2323
"autoload": {

composer.lock

Lines changed: 53 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/YiiAuthenticator.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
namespace rob006\simpleauth;
1313

14+
use yii\base\InvalidParamException;
15+
use yii\httpclient\Request;
16+
1417
/**
1518
* Helper class for authenticate \yii\httpclient\Request from yiisoft/yii2-httpclient.
19+
*
1620
* @see https://github.com/yiisoft/yii2-httpclient
1721
*
1822
* @author Robert Korulczyk <[email protected]>
@@ -22,49 +26,54 @@ class YiiAuthenticator extends Authenticator {
2226

2327
/**
2428
* {@inheritdoc}
25-
* Handle \yii\httpclient\Request from yiisoft/yii2-httpclient.
26-
* @see https://github.com/yiisoft/yii2-httpclient
2729
*
28-
* @param \yii\httpclient\Request $request Request object.
30+
* Handle `\yii\httpclient\Request` from `yiisoft/yii2-httpclient`.
31+
*
32+
* @param Request $request Request object.
2933
* @param string $method
3034
* @param string $secret Secret key used for generate token. Leave empty to use secret from
31-
* config (Yii::$app->params['simpleauth']['secret']).
32-
* @return \yii\httpclient\Request Authenticated Request object.
33-
* @throws \yii\base\InvalidParamException
35+
* config (`Yii::$app->params['simpleauth']['secret']`).
36+
* @return Request Authenticated Request object.
37+
* @throws InvalidParamException
38+
* @see https://github.com/yiisoft/yii2-httpclient
3439
*/
3540
public static function authenticate($request, $method = self::METHOD_HEADER, $secret = null) {
3641
return parent::authenticate($request, $method, $secret);
3742
}
3843

3944
/**
4045
* {@inheritdoc}
41-
* Require \yii\httpclient\Request from yiisoft/yii2-httpclient.
46+
*
47+
* Require `\yii\httpclient\Request` from yiisoft/yii2-httpclient.
48+
*
4249
* @see https://github.com/yiisoft/yii2-httpclient
4350
*/
4451
protected function validateRequest() {
45-
if (!($this->request instanceof \yii\httpclient\Request)) {
46-
throw new \yii\base\InvalidParamException('$request should be instance of \yii\httpclient\Request');
52+
if (!($this->request instanceof Request)) {
53+
throw new InvalidParamException('$request should be instance of \yii\httpclient\Request');
4754
}
4855
}
4956

5057
/**
5158
* {@inheritdoc}
5259
*/
5360
protected function authenticateByHeader() {
61+
/* @var $copy Request */
5462
$copy = clone $this->request;
5563
return $this->request->addHeaders([
56-
static::HEADER_NAME => static::generateAuthToken($copy->prepare()->getUrl(), $this->secret),
64+
static::HEADER_NAME => static::generateAuthToken($copy->prepare()->getFullUrl(), $this->secret),
5765
]);
5866
}
5967

6068
/**
6169
* {@inheritdoc}
6270
*/
6371
protected function authenticateByGetParam() {
72+
/* @var $copy Request */
6473
$copy = clone $this->request;
6574
$this->request->setMethod('get');
6675
return $this->request->setData(array_merge((array) $this->request->data, [
67-
static::PARAM_NAME => static::generateAuthToken($copy->prepare()->getUrl(), $this->secret),
76+
static::PARAM_NAME => static::generateAuthToken($copy->prepare()->getFullUrl(), $this->secret),
6877
]));
6978
}
7079

@@ -73,9 +82,10 @@ protected function authenticateByGetParam() {
7382
*/
7483
protected function authenticateByPostParam() {
7584
$this->request->setMethod('post');
85+
/* @var $copy Request */
7686
$copy = clone $this->request;
7787
return $this->request->setData(array_merge((array) $this->request->data, [
78-
static::PARAM_NAME => static::generateAuthToken($copy->prepare()->getUrl(), $this->secret),
88+
static::PARAM_NAME => static::generateAuthToken($copy->prepare()->getFullUrl(), $this->secret),
7989
]));
8090
}
8191

0 commit comments

Comments
 (0)