X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/971586c9391e1c6c0b3f6561644d8acd05f3ae8b..d78790c613a4363aa0566c357c4444e17582dc23:/src/shpub/Command/Connect.php diff --git a/src/shpub/Command/Connect.php b/src/shpub/Command/Connect.php index 68a4e18..668d7e9 100644 --- a/src/shpub/Command/Connect.php +++ b/src/shpub/Command/Connect.php @@ -47,7 +47,6 @@ class Command_Connect } $code = $authParams['code']; $userUrl = $authParams['me']; - $this->verifyAuthCode($host, $code, $state, $redirect_uri, $userUrl); $accessToken = $this->fetchAccessToken( $host, $userUrl, $code, $redirect_uri, $state @@ -98,6 +97,12 @@ class Command_Connect ) ); $res = $req->send(); + if (intval($res->getStatus() / 100) !== 2) { + Log::err('Failed to fetch access token'); + Log::err('Server responded with HTTP status code ' . $res->getStatus()); + Log::err($res->getBody()); + exit(2); + } if ($res->getHeader('content-type') != 'application/x-www-form-urlencoded') { Log::err('Wrong content type in auth verification response'); exit(2); @@ -158,39 +163,6 @@ class Command_Connect return [$redirect_uri, $socketStr]; } - protected function verifyAuthCode($host, $code, $state, $redirect_uri, $me) - { - $req = new \HTTP_Request2($host->endpoints->authorization, 'POST'); - if (version_compare(PHP_VERSION, '5.6.0', '<')) { - //correct ssl validation on php 5.5 is a pain, so disable - $req->setConfig('ssl_verify_host', false); - $req->setConfig('ssl_verify_peer', false); - } - $req->setHeader('Content-Type: application/x-www-form-urlencoded'); - $req->setBody( - http_build_query( - [ - 'code' => $code, - 'state' => $state, - 'client_id' => static::$client_id, - 'redirect_uri' => $redirect_uri, - ] - ) - ); - $res = $req->send(); - if ($res->getHeader('content-type') != 'application/x-www-form-urlencoded') { - Log::err('Wrong content type in auth verification response'); - exit(2); - } - parse_str($res->getBody(), $verifiedParams); - if (!isset($verifiedParams['me']) - || $verifiedParams['me'] !== $me - ) { - Log::err('Non-matching "me" values'); - exit(2); - } - } - protected function startHttpServer($socketStr) { $responseOk = "HTTP/1.0 200 OK\r\n"