mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-20 06:04:53 +08:00
add dynamic access token support
This commit is contained in:
parent
da134594fb
commit
94de3a27bb
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user