X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/912b60774d5a2825f39848ecde463812897e5a4d..8ed6fa09d116dc02ff089dcffe8bb177c59a9d8e:/src/shpub/Command/Connect.php diff --git a/src/shpub/Command/Connect.php b/src/shpub/Command/Connect.php index caf5acc..6ac5ed4 100644 --- a/src/shpub/Command/Connect.php +++ b/src/shpub/Command/Connect.php @@ -2,8 +2,13 @@ namespace shpub; /** - * @link http://micropub.net/draft/ - * @link http://indieweb.org/authorization-endpoint + * Connect to a micropub server to get an access token. + * + * @author Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/shpub.htm + * @link http://micropub.net/draft/ + * @link http://indieweb.org/authorization-endpoint */ class Command_Connect { @@ -33,7 +38,8 @@ class Command_Connect array( 'short_name' => '-s', 'long_name' => '--scope', - 'description' => 'Space-separated list of scopes to request (default create)', + 'description' => 'Space-separated list of scopes to request' + . ' (default: create)', 'action' => 'StoreString', 'default' => 'create', ) @@ -152,9 +158,9 @@ class Command_Connect Log::err($res->getBody()); exit(2); } - if ($res->getHeader('content-type') == 'application/x-www-form-urlencoded') { + if (Util::getMimeType($res) == 'application/x-www-form-urlencoded') { parse_str($res->getBody(), $tokenParams); - } elseif ($res->getHeader('content-type') == 'application/json') { + } elseif (Util::getMimeType($res) == 'application/json') { $tokenParams = json_decode($res->getBody(), true); } else { Log::err('Wrong content type in auth verification response'); @@ -171,11 +177,13 @@ class Command_Connect protected function getBrowserAuthUrl($host, $user, $redirect_uri, $state, $scope) { + $sep = strpos($host->endpoints->authorization, '?') === false + ? '?' : '&'; return $host->endpoints->authorization - . '?me=' . urlencode($user) + . $sep . 'me=' . urlencode($user) . '&client_id=' . urlencode(static::$client_id) . '&redirect_uri=' . urlencode($redirect_uri) - . '&state=' . $state + . '&state=' . urlencode($state) . '&scope=' . urlencode($scope) . '&response_type=code'; }