daynnnnn / statamic-forward-auth
允许您使用前向认证登录。
Requires
- statamic/cms: ^3.0 || ^4.0 || ^5.0
Requires (Dev)
- directorytree/ldaprecord: ^3.7
- orchestra/testbench: ^8.5
- pestphp/pest: ^2.6
- phpstan/phpstan: ^1.8
README
使用前向认证登录 statamic。
工作原理
安装
从标准的 Statamic 站点,您可以运行: composer require daynnnnn/statamic-forward-auth
然后发布配置: php please vendor:publish --tag="statamic-forward-authentication"
设置
首先,您需要调整 config/auth.php 文件以在用户提供者上使用前向驱动器
'users' => [
'driver' => 'forward',
],
然后,您可以编辑 config/statamic/forward-authentication.php
文件以设置认证
类型
默认情况下,有 2 个受支持的服务:http
和 ldap
这些可以通过 config/statamic/forward-authentication.php
中的 default
值进行选择
LDAP
描述
将对 base_dn
执行 ldap 搜索以查找用户。如果找到用户,则尝试使用提供的密码绑定到找到的用户。
配置
host: (array)
LDAP 主机列表
use_ssl: (bool)
是否应使用 SSL 访问主机
base_dn: (string)
查找用户的根搜索 DN
username: (string)
绑定用户 DN
password: (string)
绑定用户密码
要求
LDAP 认证服务需要 LdapRecord
composer require directorytree/ldaprecord
HTTP 认证
描述
将向端点发送一个 POST 请求,该请求包含 email
和 password
属性。预期的响应是 JSON,应包含凭据的成功状态,如果成功状态为 true,则包含用户的完整名称。
配置
endpoint: (string)
尝试登录的地址
result: (array)
在 JSON 响应中可以找到成功状态和用户的全名的地方,例如
如果您的 JSON 响应看起来像这样
{
"result": true,
"data": {
"name": "Daniel Pegg"
}
}
您的结果数组应看起来像这样
result => [
'success' => 'result',
'name' => 'data.name',
],
扩展
您还可以扩展此功能以添加自己的前向认证形式,您需要创建一个新的类,该类实现了 AuthServiceContract
接口,然后设置 config/statamic/forward-authentication.php
中的服务。对于服务,唯一的要求是驱动器定义为您的类,如下所示
'driver' => App\AuthServices\MyCustomAuthService::class,
其余的配置可以根据您自定义认证服务的需求进行设置。