/**
 * Token Auth
 */
class HTTPTokenAuth extends _BaseAuth
{
    protected $token;
    public function __construct()
    {
        $this->token = $this->get_access_token();
        $this->user_info = $this->get_user_info();
    }
    private function get_access_token()
    {
        $token = HTTP::headers()['HTTP_X_TOKEN_AUTH'];
//这儿‘HTTP_X_TOKEN_AUTH'从哪来?
        if (empty($token))
            $token = HTTP::get('access_token');
        if (empty($token)) {
            $json = HTTP::get_json_input();
            // var_dump($json);
            $token = $json['access_token'];
        }
        return $token;
    }
    public function get_user_info()
    {
        $user_info = AWS_APP::model('account')->get_user_info_by_access_token($this->token);
        return $user_info;
    }
    /**
     * @return bool
     * 检查请求是否验证通过
     */
    public function is_authorized()
    {
        if (empty($this->token))
            return false;
        if (AWS_APP::model('account')->check_access_token($this->token))
            return true;
        else
            return false;
    }
}
                                                                
                                     阅读全文
                                
                                
                                     收起全文