add dynamic access token support

This commit is contained in:
crazywhalecc 2023-01-18 01:51:14 +08:00 committed by Jerry
parent da134594fb
commit 94de3a27bb
2 changed files with 8 additions and 2 deletions

View File

@ -46,7 +46,7 @@ class Framework
public const VERSION_ID = 674;
/** @var string 版本名称 */
public const VERSION = '3.0.0-beta6';
public const VERSION = '3.0.0-beta7';
/** @var array 传入的参数 */
protected array $argv;

View File

@ -286,7 +286,13 @@ class OneBot12Adapter extends ZMPlugin
$token = $request->getQueryParams()['access_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 连接鉴权失败,拒绝接入');
$event->withResponse(HttpFactory::createResponse(401, 'Unauthorized'));
$event->stopPropagation();