diff --git a/composer.json b/composer.json index 046303f..3130ee8 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,11 @@ "require": { "php": "~8.0", "hyperf/config": "^2.2", + "hyperf/constants": "^2.2", "hyperf/di": "2.2.*", "hyperf/http-server": "2.2.*", + "hyperf/translation": "^2.2", + "hyperf/validation": "^2.2", "lightsaml/lightsaml": "^2.1", "teapot/status-code": "^1.1" }, diff --git a/publish/languages/en/saml_error.php b/publish/languages/en/saml_error.php new file mode 100644 index 0000000..bbea9b9 --- /dev/null +++ b/publish/languages/en/saml_error.php @@ -0,0 +1,16 @@ + + * Powered by PhpStorm + * Created on 2022/4/25 + */ + +return [ + 'default' => 'SAML format error', + 'params' => [ + 'default' => 'SAML parameters missing', + 'saml_request' => 'SAMLRequest is required', + ], +]; \ No newline at end of file diff --git a/publish/languages/zh_CN/saml_error.php b/publish/languages/zh_CN/saml_error.php new file mode 100644 index 0000000..0cd82a7 --- /dev/null +++ b/publish/languages/zh_CN/saml_error.php @@ -0,0 +1,16 @@ + + * Powered by PhpStorm + * Created on 2022/4/25 + */ + +return [ + 'default' => 'SAML 检验失败', + 'params' => [ + 'default' => 'SAML 参数校验失败', + 'saml_request' => 'SAMLRequest 参数不能为空', + ], +]; \ No newline at end of file diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 8361055..b4a7ffa 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -41,7 +41,19 @@ class ConfigProvider // 建议默认配置放在 publish 文件夹中,文件命名和组件名称相同 'source' => __DIR__ . '/../publish/saml.php', // 对应的配置文件路径 'destination' => BASE_PATH . '/config/autoload/saml.php', // 复制为这个路径下的该文件 - ] + ], + [ + 'id' => 'languages_cn', + 'description' => 'The SAML error message for Chinese', + 'source' => __DIR__ . '/../publish/languages/zh_CN/saml_error.php', + 'destination' => BASE_PATH . '/storage/languages/zh_CN/saml_error.php' + ], + [ + 'id' => 'languages_en', + 'description' => 'The SAML error message for English', + 'source' => __DIR__ . '/../publish/languages/en/saml_error.php', + 'destination' => BASE_PATH . '/storage/languages/en/saml_error.php' + ], ], ]; } diff --git a/src/Constants/SamlErrorCode.php b/src/Constants/SamlErrorCode.php new file mode 100644 index 0000000..7f9d50d --- /dev/null +++ b/src/Constants/SamlErrorCode.php @@ -0,0 +1,42 @@ + + * Powered by PhpStorm + * Created on 2022/4/25 + */ + +namespace Singularity\HyperfSaml\Constants; + +use Hyperf\Constants\AbstractConstants; + +/** + * SAML 相关错误码 + * Singularity\HyperfSaml\Constants\SamlErrorCode@HyperfSaml + * + * @author 李东云 + * Powered by PhpStorm + * Created on 2022/4/25 + */ +class SamlErrorCode extends AbstractConstants +{ + + // 203 SAML 鉴权 + /** + * @Message("saml_error.auth.saml.default") + */ + public const AUTH_SAML_ERROR = 203000; + + // 20301 验证 + /** + * @Message("saml_error.auth.saml.params.default") + */ + public const AUTH_SAML_REQUEST_PARAMS_ERROR = 2030100; + + /** + * @Message("saml_error.auth.saml.params.saml_request") + */ + public const AUTH_SAML_REQUEST_PARAMS_SAML_REQUEST = 2030101; + +} \ No newline at end of file