mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 23:25:35 +08:00
add dynamic access token support
This commit is contained in:
@@ -46,7 +46,7 @@ class Framework
|
|||||||
public const VERSION_ID = 674;
|
public const VERSION_ID = 674;
|
||||||
|
|
||||||
/** @var string 版本名称 */
|
/** @var string 版本名称 */
|
||||||
public const VERSION = '3.0.0-beta6';
|
public const VERSION = '3.0.0-beta7';
|
||||||
|
|
||||||
/** @var array 传入的参数 */
|
/** @var array 传入的参数 */
|
||||||
protected array $argv;
|
protected array $argv;
|
||||||
|
|||||||
@@ -286,7 +286,13 @@ class OneBot12Adapter extends ZMPlugin
|
|||||||
$token = $request->getQueryParams()['access_token'] ?? '';
|
$token = $request->getQueryParams()['access_token'] ?? '';
|
||||||
}
|
}
|
||||||
$token = explode('Bearer ', $token);
|
$token = explode('Bearer ', $token);
|
||||||
if (!isset($token[1]) || $token[1] !== $stored_token) { // 没有 token,鉴权失败
|
// 动态和静态鉴权
|
||||||
|
if ($stored_token instanceof \Closure) {
|
||||||
|
$stored_token = $stored_token($token[1] ?? null);
|
||||||
|
} else {
|
||||||
|
$stored_token = !isset($token[1]) || $token[1] !== $stored_token;
|
||||||
|
}
|
||||||
|
if (!$stored_token) { // 没有 token,鉴权失败
|
||||||
logger()->warning('OneBot 12 反向 WS 连接鉴权失败,拒绝接入');
|
logger()->warning('OneBot 12 反向 WS 连接鉴权失败,拒绝接入');
|
||||||
$event->withResponse(HttpFactory::createResponse(401, 'Unauthorized'));
|
$event->withResponse(HttpFactory::createResponse(401, 'Unauthorized'));
|
||||||
$event->stopPropagation();
|
$event->stopPropagation();
|
||||||
|
|||||||
Reference in New Issue
Block a user