public function authenticate(HTTPRequest $request)
    {
        //get the token
        $token = $request->getHeader($this->tokenConfig['header']);
        if (!$token) {
            $token = $request->requestVar($this->tokenConfig['queryVar']);
        }

        if ($token) {
            //check token validity
            return $this->validateAPIToken($token, $request);
        } else {
            //no token, bad news
            return new RESTfulAPIError(403,
                'Token invalid.',
                array(
                    'message' => 'Token invalid.',
                    'code' => self::AUTH_CODE_TOKEN_INVALID,
                )
            );
        }
    }