final public static function toOAuth2(ServerRequestInterface $request)
    {
        $contents = $request->getBody()->getContents();
        $request->getBody()->rewind();

        return new OAuth2\Request(
            (array)$request->getQueryParams(),
            (array)$request->getParsedBody(),
            $request->getAttributes(),
            $request->getCookieParams(),
            self::convertUploadedFiles($request->getUploadedFiles()),
            $request->getServerParams(),
            $contents,
            self::cleanupHeaders($request->getHeaders())
        );
    }