PHP Chaos

5.15-Yii-QueryParamAuth.php-Use

2019-05-15  本文已影响0人  xiaojianxu

What steps will reproduce the problem?

        public function behaviors()
    {
        $behaviors = parent::behaviors();
        
        $behaviors['authenticator'] = [
        'class' => QueryParamAuth::className(),
        'except' => ['login','logout']
        ];

        return $behaviors;
    }

What is the expected result?

When I pass the query parameter in the url , such as

http://backend.test/commons?access-token=x2qwgZPIQTW6Et-SQnDgdly6BJHJttGx

Then I will get the reponse from the controller instead of

"data": {
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\web\UnauthorizedHttpException"
}

What do you get instead?

use request andrequest->get print in QueryParamAuth.php. There is

/**
     * {@inheritdoc}
     */
    public function authenticate($user, $request, $response)
    {
        print_r($request);
        print_r($request->get());
        exit;

[_url:yii\web\Request:private] => /commons?access-token=x2qwgZPIQTW6Et-SQnDgdly6BJHJttGx

Array
(
[/commons] =>
)

Additional info

Q A
Yii version This is Yii version 2.0.18-dev.
PHP version PHP 7.1
Operating system Windows 7

This issue had been fixed.

#15305 (comment)

Apache - .htaccess

Replace RewriteRule ^(.*)$ /index.php?/$1 [L] by RewriteRule . index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule . index.php
empty-access-token.png with-access-token.png
上一篇下一篇

猜你喜欢

热点阅读