commit 2a541a14876bf07a63986cdec77691af12ab1889
Author: Wolfgang Ziegler // fago <fago@wolfgangziegler.net>
Date:   Mon May 13 18:29:32 2019 +0200

    Issue #3028507: Add drush command to generate keys.

diff --git a/composer.json b/composer.json
index b5cfca2..8d7ac00 100644
--- a/composer.json
+++ b/composer.json
@@ -12,5 +12,12 @@
             "name": "Mateu Aguiló Bosch",
             "email": "mateu.aguilo.bosch@gmail.com"
         }
-    ]
+    ],
+    "extra": {
+        "drush": {
+            "services": {
+                "drush.services.yml": "^9"
+            }
+        }
+    }
 }
diff --git a/src/Commands/SimpleOauthCommands.php b/src/Commands/SimpleOauthCommands.php
new file mode 100644
index 0000000..52be47b
--- /dev/null
+++ b/src/Commands/SimpleOauthCommands.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\simple_oauth\Commands;
+
+use Drush\Commands\DrushCommands;
+
+/**
+ * Class SimpleOauthCommands
+ * @package Drupal\simple_oauth\Commands
+ */
+class SimpleOauthCommands extends DrushCommands {
+
+  /**
+   * Generate Oauth2 Keys.
+   *
+   * @param string $keypath The path were the key files will be saved.
+   * @command simple-oauth:generate-keys
+   * @validate-module-enabled simple_oauth
+   * @aliases so:generate-keys, sogk
+   */
+  public function generateKeys($keypath) {
+    $dir_name = $keypath;
+    /** @var \Drupal\simple_oauth\Service\KeyGeneratorService $key_gen */
+    $key_gen = \Drupal::service('simple_oauth.key.generator');
+    /** @var \Symfony\Component\Filesystem\Filesystem $file_system */
+    $file_system = \Drupal::service('file_system');
+
+    $relative_path = DRUPAL_ROOT . DIRECTORY_SEPARATOR . $dir_name;
+    if (!$file_system->isDirectory($relative_path)) {
+      $file_system->mkdir($relative_path);
+    }
+    $keys_path = $file_system->realpath($relative_path);
+
+    $key_gen->generateKeys($keys_path);
+  }
+}
