Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cuiyuanzhe opened this issue Oct 21, 2024 · 5 comments
Open

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

cuiyuanzhe opened this issue Oct 21, 2024 · 5 comments
Labels
question Further information is requested

Comments

@cuiyuanzhe
Copy link

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

@cuiyuanzhe cuiyuanzhe added the question Further information is requested label Oct 21, 2024
@EAGLE50
Copy link

EAGLE50 commented Oct 22, 2024

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

@cuiyuanzhe
Copy link
Author

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

@cuiyuanzhe
Copy link
Author

@EAGLE50

@LauraGPT
Copy link
Collaborator

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

@EAGLE50
Copy link

EAGLE50 commented Oct 24, 2024

@EAGLE50

std::string req_path = "";
wss_server::connection_ptr wss_con;
server::connection_ptr con;
if (is_ssl) {
wss_con = wss_server_->get_con_from_hdl(hdl);
req_path = con->get_resource();
} 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的请求。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants