modelscope / FunASR

A Fundamental End-to-End Speech Recognition Toolkit and Open Source SOTA Pretrained Models, Supporting Speech Recognition, Voice Activity Detection, Text Post-processing etc.
https://www.funasr.com
Other
7.08k stars 755 forks source link

C++服务端WebSocket添加鉴权功能 #2161

Open cuiyuanzhe opened 1 month ago

cuiyuanzhe commented 1 month ago

C++服务端如何添加鉴权功能? 有哪个大佬说一下在哪里添加吗?

EAGLE50 commented 1 month ago

我是游客哈,非官方的。 可以考虑在 funasr-wss-server-2pass.cpp 文件中添加。位置放在下载模型之前。 可以搜索下面那一行注释来在文件中定位。 // Download model form Modelscope

cuiyuanzhe commented 1 month ago

能贴个代码么,我在on_open方法里加的,但是一直运行报错,离开学校就再没有摸过C++了

cuiyuanzhe commented 1 month ago

@EAGLE50

LauraGPT commented 1 month ago

简单的找个大模型助手就搞定了,代码都不超过5行

EAGLE50 commented 1 month ago

@EAGLE50

std::string req_path = ""; wss_server::connection_ptr wss_con; server::connection_ptr con; if (is_ssl) { wss_con = wssserver->get_con_from_hdl(hdl); req_path = con->getresource(); } else { con = server->get_con_from_hdl(hdl); req_path = con->get_resource(); } //此处加内容。记得鉴权失败后,要调用下close()函数,并返回return; if (req_path.find("/xxx/funasr") != 0) { LOG(INFO) << "EAGLE bad req_path .. refuse connection. con.close(bad_gateway)"; if (is_ssl) { wss_con->close(websocketpp::close::status::bad_gateway, "bad uri hope..."); } else { con->close(websocketpp::close::status::bad_gateway, "bad uri hope..."); } return; }

在on_open函数里,代码示例是只接受特定URL的请求。