Przeglądaj źródła

feat(auth): 引入配置类以管理SSL验证选项

新增 `Config` 类用于管理扩展的配置项,包括 `verify_peer` 和 `verify_host` 两个选项。将原本通过环境变量 `IS_DDEV_PROJECT` 控制的SSL验证逻辑,改为通过配置项灵活控制。同时在 `config.php` 中增加对应的配置字段,支持在后台界面中进行设置。
此变更提高了配置的可维护性和灵活性。
runphp 6 miesięcy temu
rodzic
commit
33ddafcc54
4 zmienionych plików z 60 dodań i 5 usunięć
  1. 34 0
      config.php
  2. 20 0
      src/Config.php
  3. 2 0
      src/Extension.php
  4. 4 5
      src/Hook/AppStatusHook.php

+ 34 - 0
config.php

@@ -33,4 +33,38 @@ return [
         'hidden' => false,
         'info' => '应用市场API密钥',
     ],
+    [
+        'type' => 'switch',
+        'field' => 'verify_peer',
+        'title' => '验证服务器证书',
+        'info' => '是否验证服务器证书',
+        '$required' => false,
+        'props' => [
+            'activeValue' => true,
+            'inactiveValue' => false
+        ],
+        '_fc_id' => 'id_verify_peer',
+        'name' => 'ref_verify_peer',
+        'display' => true,
+        'hidden' => false,
+        '_fc_drag_tag' => 'switch',
+        'value' => true
+    ],
+    [
+        'type' => 'switch',
+        'field' => 'verify_host',
+        'title' => '验证主机名',
+        'info' => '是否验证证书中的主机名',
+        '$required' => false,
+        'props' => [
+            'activeValue' => true,
+            'inactiveValue' => false
+        ],
+        '_fc_id' => 'id_verify_host',
+        'name' => 'ref_verify_host',
+        'display' => true,
+        'hidden' => false,
+        '_fc_drag_tag' => 'switch',
+        'value' => true
+    ]
 ];

+ 20 - 0
src/Config.php

@@ -0,0 +1,20 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Auth;
+
+use SixShop\System\Trait\ConfigTrait;
+
+/**
+ * @property bool $verify_peer 验证服务器证书
+ * @property bool $verify_host 验证主机名
+ */
+class Config
+{
+    use ConfigTrait;
+
+    public function getExtensionID(): string
+    {
+        return Extension::EXTENSION_ID;
+    }
+}

+ 2 - 0
src/Extension.php

@@ -10,6 +10,8 @@ use SixShop\Auth\Hook\AppStatusHook;
 
 class Extension extends ExtensionAbstract
 {
+    const EXTENSION_ID = 'auth';
+
     public function getHooks(): array
     {
         return [

+ 4 - 5
src/Hook/AppStatusHook.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 namespace SixShop\Auth\Hook;
 
 use Composer\Factory;
+use SixShop\Auth\Config;
 use SixShop\Core\Attribute\Hook;
 use Symfony\Component\HttpClient\Exception\ClientException;
 use Symfony\Component\HttpClient\HttpClient;
@@ -21,7 +22,7 @@ class AppStatusHook
 
     private HttpClientInterface $httpClient;
     public function __construct(
-        private readonly Env $env,
+        private readonly Config $config,
     )
     {
         $authConfigSource = Factory::createConfig()->getAuthConfigSource();
@@ -35,10 +36,8 @@ class AppStatusHook
             'base_uri' => self::BASE_URL,
             'headers' => ['Authorization' => 'Bearer ' . $bearerToken],
         ];
-        if ($this->env->get('IS_DDEV_PROJECT') === true) {
-            $defaultOptions['verify_peer'] = false;
-            $defaultOptions['verify_host'] = false;
-        }
+        $defaultOptions['verify_peer'] = $this->config->verify_peer;
+        $defaultOptions['verify_host'] = $this->config->verify_host;
         $this->httpClient = HttpClient::create($defaultOptions);
 
     }