美文网首页PHP Chaos
5.15-Yii-QueryParamAuth.php-Use

5.15-Yii-QueryParamAuth.php-Use

作者: xiaojianxu | 来源:发表于2019-05-15 15:55 被阅读0次

    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

    相关文章

      网友评论

        本文标题:5.15-Yii-QueryParamAuth.php-Use

        本文链接:https://www.haomeiwen.com/subject/zcapaqtx.html