aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2022-07-15 11:47:35 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2022-07-15 11:47:35 +0000
commit55852ef4819e5eafce9ae53dc4de2d84cdad1778 (patch)
tree9aedcdf89f416a7936f7df80da339a537082b5d5 /db
parenta9585dad3547a4ebbadd00f44065f95017d18684 (diff)
StEP-366: Add OAuth2 support to Stud.IP
Closes #1035 and #1198 Merge request studip/studip!635
Diffstat (limited to 'db')
-rw-r--r--db/migrations/5.2.15_create_oauth2_tables.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/db/migrations/5.2.15_create_oauth2_tables.php b/db/migrations/5.2.15_create_oauth2_tables.php
new file mode 100644
index 0000000..460d4e0
--- /dev/null
+++ b/db/migrations/5.2.15_create_oauth2_tables.php
@@ -0,0 +1,83 @@
+<?php
+
+class CreateOauth2Tables extends Migration
+{
+ public function description()
+ {
+ return 'creates all necessary tables for the OAuth2 plugin';
+ }
+
+ public function up()
+ {
+ $db = DBManager::get();
+
+ $query = "CREATE TABLE IF NOT EXISTS `oauth2_access_tokens` (
+ `id` VARCHAR(100) NOT NULL,
+ `user_id` CHAR(32) COLLATE `latin1_bin` NULL,
+ `client_id` BIGINT UNSIGNED NOT NULL,
+ `scopes` TEXT NULL,
+ `revoked` TINYINT(1) NOT NULL DEFAULT 0,
+ `expires_at` INT(11) NULL,
+ `mkdate` INT(11) NOT NULL,
+ `chdate` INT(11) NOT NULL,
+
+ PRIMARY KEY (`id`),
+ KEY `user_id` (`user_id`)
+ )";
+ $db->exec($query);
+
+ $query = "CREATE TABLE IF NOT EXISTS `oauth2_auth_codes` (
+ `id` VARCHAR(100) NOT NULL,
+ `user_id` CHAR(32) COLLATE `latin1_bin` NOT NULL,
+ `client_id` BIGINT UNSIGNED NOT NULL,
+ `scopes` TEXT NULL,
+ `revoked` TINYINT(1) NOT NULL DEFAULT 0,
+ `expires_at` INT(11) NULL,
+ `mkdate` INT(11) NOT NULL,
+ `chdate` INT(11) NOT NULL,
+
+ PRIMARY KEY (`id`),
+ KEY `user_id` (`user_id`)
+ )";
+ $db->exec($query);
+
+ $query = "CREATE TABLE IF NOT EXISTS `oauth2_clients` (
+ `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(255) NOT NULL,
+ `secret` VARCHAR(100) NULL,
+ `redirect` TEXT NOT NULL,
+ `revoked` TINYINT(1) NOT NULL DEFAULT 0,
+
+ `description` TEXT NULL,
+ `owner` VARCHAR(255) NULL,
+ `homepage` VARCHAR(255) NULL,
+ `admin_notes` TEXT NULL,
+
+ `mkdate` INT(11) NOT NULL,
+ `chdate` INT(11) NOT NULL,
+
+ PRIMARY KEY (`id`)
+ )";
+ $db->exec($query);
+
+ $query = "CREATE TABLE IF NOT EXISTS `oauth2_refresh_tokens` (
+ `id` VARCHAR(100) NOT NULL,
+ `access_token_id` VARCHAR(100) NOT NULL,
+ `revoked` TINYINT(1) NOT NULL DEFAULT 0,
+ `expires_at` INT(11) NULL,
+
+ PRIMARY KEY (`id`),
+ KEY `access_token_id` (`access_token_id`)
+ )";
+ $db->exec($query);
+ }
+
+ public function down()
+ {
+ $db = \DBManager::get();
+ $db->exec('DROP TABLE IF EXISTS `oauth2_access_tokens`');
+ $db->exec('DROP TABLE IF EXISTS `oauth2_auth_codes`');
+ $db->exec('DROP TABLE IF EXISTS `oauth2_clients`');
+ $db->exec('DROP TABLE IF EXISTS `oauth2_refresh_tokens`');
+ }
+}