1111
1212namespace 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