鍍金池/ 問答/PHP/ yii restful api 認證問題

yii restful api 認證問題

1.使用yii 的restful api 接口認證傳遞正確的access-token驗證一直無法通過圖片描述,配置文件配置圖片描述,API的behavior配置如下圖片描述,現(xiàn)在驗證optional以外的方法需要傳遞access-token進行驗證,傳遞了正確的access-token的值,還是一直提示401,麻煩有人知道是什么原因嗎,謝謝

回答
編輯回答
薔薇花

在 user 里面添加

    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken($token, $type = null)
    {
                //if ($type == '')
        // throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
        //return static::findOne(['access_token'=>$token , 'status' => self::STATUS_ACTIVE],>;
        return static::find()
        ->where(['access_token'=>$token , 'status' => self::STATUS_ACTIVE])
        ->andWhere(['>','expire_at',time()]) 
        ->one();
        // throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
    }
2018年7月29日 11:24