Kaynağa Gözat

#762 OAuth2: minor refactoring

Alex Trofimov 9 yıl önce
ebeveyn
işleme
cbd8c4bd36

+ 2 - 2
modules/boonex/oauth2/classes/BxOAuthFormAdd.php

@@ -11,8 +11,8 @@
 
 
 class BxOAuthFormAdd extends BxTemplFormView
 class BxOAuthFormAdd extends BxTemplFormView
 {
 {
-    protected static $LENGTH_ID = 10;
-    protected static $LENGTH_SECRET = 32;
+    public static $LENGTH_ID = 10;
+    public static $LENGTH_SECRET = 32;
 
 
     protected $_sModule;
     protected $_sModule;
     protected $_oModule;
     protected $_oModule;

+ 23 - 0
modules/boonex/oauth2/classes/BxOAuthModule.php

@@ -204,6 +204,29 @@ class BxOAuthModule extends BxDolModule
 
 
     function serviceAddClient ($aClient)
     function serviceAddClient ($aClient)
     {
     {
+        if (!isset($aClient['client_id'])) {
+            bx_import('FormAdd', 'bx_oauth');
+            for ($i = 0; $i < 99 ; ++$i) {
+                $aClient['client_id'] = strtolower(genRndPwd(BxOAuthFormAdd::$LENGTH_ID, false));
+                if (!$this->_oDb->getClientTitle($aClient['client_id'])) // check for uniq
+                    break;
+            }
+        }
+
+        if (!isset($aClient['client_secret'])) {
+            bx_import('FormAdd', 'bx_oauth');
+            $aClient['client_secret'] = strtolower(genRndPwd(BxOAuthFormAdd::$LENGTH_SECRET, false));
+        }
+
+        if (!isset($aClient['scope']))
+            $aClient['scope'] = 'market';
+
+        if (!isset($aClient['user_id']))
+            $aClient['user_id'] = bx_get_logged_profile_id();
+
+        if (!isset($aClient['title']) && isset($aClient['redirect_uri']) && ($sHost = parse_url($aClient['redirect_uri'], PHP_URL_HOST)))
+            $aClient['title'] = $sHost;
+
     	return $this->_oDb->addClient($aClient);
     	return $this->_oDb->addClient($aClient);
     }
     }