public function index(): HTTPResponse
    {
        $body = null;
        $contentType = $this->getRequest()->getHeader('Content-Type');

        if ($contentType === 'application/json') {
            $body = json_decode($this->getRequest()->getBody(), true);
        } else {
            $body = $this->getRequest()->postVars();
        }

        if (empty($body)) {
            return $this->getErrorResponse(
                'No parameters could be found in request body. Did you correctly set the Content-Type header?',
                500
            );
        }

        // request needs parsed body
        $psrRequest = (new HttpRequestAdapter())->toPsr7($this->getRequest())
            ->withParsedBody($body);
        $psrResponse = new Response();

        $authServer = $this->serverGenerator->getServer();

        try {
            return (new HttpResponseAdapter())
                ->fromPsr7($authServer->respondToAccessTokenRequest($psrRequest, $psrResponse));
        } catch (OAuthServerException $e) {
            return $this->convertResponse($e->generateHttpResponse(new Response()));
        } catch (Exception $e) {
            return $this->getErrorResponse($e->getMessage());
        }
    }