Add "scope" option to connect command
[shpub.git] / src / shpub / Command / Connect.php
index 748e905f73ee64a9dba2ee8e83bf77b8fe835b58..caf5acc12a23dce8f4cef22fd9b26905ef8dbd18 100644 (file)
@@ -28,6 +28,16 @@ class Command_Connect
                 'default'     => false,
             )
         );
+        $cmd->addOption(
+            'scope',
+            array(
+                'short_name'  => '-s',
+                'long_name'   => '--scope',
+                'description' => 'Space-separated list of scopes to request (default create)',
+                'action'      => 'StoreString',
+                'default'     => 'create',
+            )
+        );
         $cmd->addArgument(
             'server',
             [
@@ -51,7 +61,7 @@ class Command_Connect
         );
     }
 
-    public function run($server, $user, $newKey, $force)
+    public function run($server, $user, $newKey, $force, $scope)
     {
         $server = Validator::url($server, 'server');
         if ($user === null) {
@@ -75,7 +85,7 @@ class Command_Connect
         $state = time();
         Log::msg(
             "To authenticate, open the following URL:\n"
-            . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state)
+            . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state, $scope)
         );
 
         $authParams = $this->startHttpServer($socketStr);
@@ -159,14 +169,14 @@ class Command_Connect
         return $accessToken;
     }
 
-    protected function getBrowserAuthUrl($host, $user, $redirect_uri, $state)
+    protected function getBrowserAuthUrl($host, $user, $redirect_uri, $state, $scope)
     {
         return $host->endpoints->authorization
             . '?me=' . urlencode($user)
             . '&client_id=' . urlencode(static::$client_id)
             . '&redirect_uri=' . urlencode($redirect_uri)
             . '&state=' . $state
-            . '&scope=post'
+            . '&scope=' . urlencode($scope)
             . '&response_type=code';
     }