public function authenticate($code)
    {
        if (empty($code)) {
            throw new NostoException('Invalid authentication token');
        }

        $request = new HttpRequest();
        $request->setUrl(Nosto::getOAuthBaseUrl() . self::PATH_TOKEN);
        $request->setReplaceParams(
            array(
                '{cid}' => $this->clientId,
                '{sec}' => $this->clientSecret,
                '{uri}' => $this->redirectUrl,
                '{cod}' => $code
            )
        );
        $response = $request->get();
        $result = $response->getJsonResult(true);

        if ($response->getCode() !== 200) {
            throw ExceptionBuilder::fromHttpRequestAndResponse($request, $response);
        }
        if (empty($result['access_token'])) {
            throw new NostoException('No "access_token" returned after authenticating with code');
        }
        if (empty($result['merchant_name'])) {
            throw new NostoException('No "merchant_name" returned after authenticating with code');
        }

        return NostoOAuthToken::create($result);
    }