Преглед изворни кода

Modules updates: OAuth2 Server

AntonLV пре 3 година
родитељ
комит
c3e2948efe

+ 1 - 1
modules/boonex/oauth2/install/config.php

@@ -17,7 +17,7 @@ $aConfig = array(
     'name' => 'bx_oauth',
     'title' => 'OAuth2 Server',
     'note' => 'Allow to use site user credentials and basic API',
-    'version' => '13.0.3.DEV',
+    'version' => '13.0.4.DEV',
     'vendor' => 'BoonEx',
     'help_url' => 'http://feed.una.io/?section={module_name}',
 

+ 51 - 0
modules/boonex/oauth2/updates/13.0.2_13.0.3/install/config.php

@@ -0,0 +1,51 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ */
+
+$aConfig = array(
+    /**
+     * Main Section.
+     */
+    'title' => 'OAuth2 Server',
+    'version_from' => '13.0.2',
+    'version_to' => '13.0.3',
+    'vendor' => 'BoonEx',
+
+    'compatible_with' => array(
+        '13.1.0-B1'
+    ),
+
+    /**
+     * 'home_dir' and 'home_uri' - should be unique. Don't use spaces in 'home_uri' and the other special chars.
+     */
+    'home_dir' => 'boonex/oauth2/updates/update_13.0.2_13.0.3/',
+    'home_uri' => 'oauth2_update_1302_1303',
+
+    'module_dir' => 'boonex/oauth2/',
+    'module_uri' => 'oauth2',
+
+    'db_prefix' => 'bx_oauth_',
+    'class_prefix' => 'BxOAuth',
+
+    /**
+     * Installation/Uninstallation Section.
+     */
+    'install' => array(
+        'execute_sql' => 1,
+        'update_files' => 1,
+        'update_languages' => 0,
+        'clear_db_cache' => 1,
+    ),
+
+    /**
+     * Category for language keys.
+     */
+    'language_category' => 'OAuth2 Server',
+
+    /**
+     * Files Section
+     */
+    'delete_files' => array(),
+);

+ 27 - 0
modules/boonex/oauth2/updates/13.0.2_13.0.3/install/installer.php

@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ */
+
+class BxOAuthUpdater extends BxDolStudioUpdater
+{
+    function __construct($aConfig)
+    {
+        parent::__construct($aConfig);
+    }
+
+    public function actionExecuteSql($sOperation)
+    {
+        if($sOperation == 'install') {
+            if(!$this->oDb->isFieldExists('bx_oauth_authorization_codes', 'id_token'))
+                $this->oDb->query("ALTER TABLE `bx_oauth_authorization_codes` ADD `id_token` varchar(1000) DEFAULT NULL AFTER `scope`");
+            if(!$this->oDb->isFieldExists('bx_oauth_authorization_codes', 'code_challenge'))
+                $this->oDb->query("ALTER TABLE `bx_oauth_authorization_codes` ADD `code_challenge` varchar(1000) DEFAULT NULL AFTER `id_token`");
+            if(!$this->oDb->isFieldExists('bx_oauth_authorization_codes', 'code_challenge_method'))
+                $this->oDb->query("ALTER TABLE `bx_oauth_authorization_codes` ADD `code_challenge_method` varchar(20) DEFAULT NULL AFTER `code_challenge`");
+        }
+
+        return parent::actionExecuteSql($sOperation);
+    }
+}

+ 1 - 0
modules/boonex/oauth2/updates/13.0.2_13.0.3/install/sql/install.sql

@@ -0,0 +1 @@
+SET @sName = 'bx_oauth';

+ 68 - 0
modules/boonex/oauth2/updates/13.0.2_13.0.3/source/install/config.php

@@ -0,0 +1,68 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    OAuth2 OAuth2 server
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+$aConfig = array(
+    /**
+     * Main Section.
+     */
+    'type' => BX_DOL_MODULE_TYPE_MODULE,
+    'name' => 'bx_oauth',
+    'title' => 'OAuth2 Server',
+    'note' => 'Allow to use site user credentials and basic API',
+    'version' => '13.0.3',
+    'vendor' => 'BoonEx',
+    'help_url' => 'http://feed.una.io/?section={module_name}',
+
+    'compatible_with' => array(
+        '13.1.0-B1'
+    ),
+
+    /**
+     * 'home_dir' and 'home_uri' - should be unique. Don't use spaces in 'home_uri' and the other special chars.
+     */
+    'home_dir' => 'boonex/oauth2/',
+    'home_uri' => 'oauth2',
+
+    'db_prefix' => 'bx_oauth_',
+    'class_prefix' => 'BxOAuth',
+
+    /**
+     * Category for language keys.
+     */
+    'language_category' => 'OAuth2 Server',
+
+    /**
+     * Installation/Uninstallation Section.
+     */
+    'install' => array(
+        'execute_sql' => 1,
+        'update_languages' => 1,
+    ),
+    'uninstall' => array (
+        'execute_sql' => 1,
+        'update_languages' => 1,
+    ),
+    'enable' => array(
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+    'disable' => array (
+        'execute_sql' => 1,
+        'clear_db_cache' => 1,
+    ),
+
+    /**
+     * Dependencies Section
+     */
+    'dependencies' => array(),
+);
+
+/** @} */

+ 81 - 0
modules/boonex/oauth2/updates/13.0.2_13.0.3/source/install/sql/install.sql

@@ -0,0 +1,81 @@
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_access_tokens` (
+  `access_token` varchar(40) NOT NULL,
+  `client_id` varchar(80) NOT NULL,
+  `user_id` int(10) unsigned DEFAULT NULL,
+  `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `scope` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`access_token`)
+);
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_authorization_codes` (
+  `authorization_code` varchar(40) NOT NULL,
+  `client_id` varchar(80) NOT NULL,
+  `user_id` int(10) unsigned DEFAULT NULL,
+  `redirect_uri` varchar(255) DEFAULT NULL,
+  `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `scope` varchar(255) DEFAULT NULL,
+  `id_token` varchar(1000) DEFAULT NULL,
+  `code_challenge` varchar(1000) DEFAULT NULL,
+  `code_challenge_method` varchar(20) DEFAULT NULL
+  PRIMARY KEY (`authorization_code`),
+  KEY `user_id` (`user_id`)
+);
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_clients` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `title` varchar(255) NOT NULL,
+  `client_id` varchar(80) NOT NULL,
+  `client_secret` varchar(80) DEFAULT NULL,
+  `redirect_uri` varchar(255) NOT NULL,
+  `grant_types` varchar(80) DEFAULT NULL,
+  `scope` varchar(255) DEFAULT NULL,
+  `parent_id` int(10) unsigned DEFAULT 0,
+  `user_id` int(10) unsigned DEFAULT 0,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `client_id` (`client_id`)
+);
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_allowed_origins` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `client_id` int(11) NOT NULL,
+  `url` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`),
+  KEY `url` (`url`(191))
+);
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_refresh_tokens` (
+  `refresh_token` varchar(40) NOT NULL,
+  `client_id` varchar(80) NOT NULL,
+  `user_id` int(10) unsigned DEFAULT NULL,
+  `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `scope` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`refresh_token`),
+  KEY `user_id` (`user_id`)
+);
+
+CREATE TABLE IF NOT EXISTS `bx_oauth_scopes` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `scope` varchar(255)  DEFAULT NULL,
+  `is_default` tinyint(1) DEFAULT NULL,
+   PRIMARY KEY (`id`)
+);
+
+INSERT INTO `bx_oauth_scopes` (`scope`, `is_default`) VALUES
+('basic', 1),
+('service', 0),
+('market', 0);
+
+-- Studio page and widget
+
+INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
+(3, 'bx_oauth', '_bx_oauth', '_bx_oauth', 'bx_oauth@modules/boonex/oauth2/|std-icon.svg');
+SET @iPageId = LAST_INSERT_ID();
+
+SET @iParentPageId = (SELECT `id` FROM `sys_std_pages` WHERE `name` = 'home');
+SET @iParentPageOrder = (SELECT MAX(`order`) FROM `sys_std_pages_widgets` WHERE `page_id` = @iParentPageId);
+INSERT INTO `sys_std_widgets` (`page_id`, `module`, `type`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`) VALUES
+(@iPageId, 'bx_oauth', 'integrations', '{url_studio}module.php?name=bx_oauth&page=settings', '', 'bx_oauth@modules/boonex/oauth2/|std-icon.svg', '_bx_oauth', '', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:11:"get_actions";s:6:"params";a:0:{}s:5:"class";s:18:"TemplStudioModules";}');
+INSERT INTO `sys_std_pages_widgets` (`page_id`, `widget_id`, `order`) VALUES
+(@iParentPageId, LAST_INSERT_ID(), IF(ISNULL(@iParentPageOrder), 1, @iParentPageOrder + 1));
+