Add "scope" option to connect command
authorAaron Parecki <aaron@parecki.com>
Wed, 22 Mar 2017 17:56:09 +0000 (10:56 -0700)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 23 Mar 2017 06:41:00 +0000 (07:41 +0100)
src/shpub/Cli.php
src/shpub/Command/Connect.php

index 6935c1c3f7f962e49b2dabb10005a7fe5ebcae0f..24207a108f71f0e76d1107567aeb3aef7bae5d4e 100644 (file)
@@ -24,7 +24,8 @@ class Cli
                     $res->command->args['server'],
                     $res->command->args['user'],
                     $res->command->args['key'],
-                    $res->command->options['force']
+                    $res->command->options['force'],
+                    $res->command->options['scope']
                 );
                 break;
 
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';
     }