fixed headers bug
This commit is contained in:
parent
cf3a4cd07c
commit
c339c6c6bd
2 changed files with 4 additions and 3 deletions
|
|
@ -365,7 +365,8 @@ void websocketSetup(const String& server_domain, int port, const String& path)
|
||||||
{
|
{
|
||||||
const String headers =
|
const String headers =
|
||||||
"Authorization: Bearer " + String(authTokenGlobal) + "\r\n" +
|
"Authorization: Bearer " + String(authTokenGlobal) + "\r\n" +
|
||||||
"mac_address: " + WiFi.macAddress() + "\r\n";
|
"X-Wifi-Rssi: " + String(WiFi.RSSI()) + "\r\n" +
|
||||||
|
"X-Device-Mac: " + WiFi.macAddress();
|
||||||
|
|
||||||
xSemaphoreTake(wsMutex, portMAX_DELAY);
|
xSemaphoreTake(wsMutex, portMAX_DELAY);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ server.on("upgrade", async (req, socket, head) => {
|
||||||
const {
|
const {
|
||||||
authorization: authHeader,
|
authorization: authHeader,
|
||||||
"x-wifi-rssi": rssi,
|
"x-wifi-rssi": rssi,
|
||||||
mac_address,
|
"x-device-mac": deviceMac,
|
||||||
} = req.headers;
|
} = req.headers;
|
||||||
authToken = authHeader?.replace("Bearer ", "") ?? "";
|
authToken = authHeader?.replace("Bearer ", "") ?? "";
|
||||||
const wifiStrength = parseInt(rssi as string); // Convert to number
|
const wifiStrength = parseInt(rssi as string); // Convert to number
|
||||||
|
|
@ -143,7 +143,7 @@ server.on("upgrade", async (req, socket, head) => {
|
||||||
user = await authenticateUser(supabase, authToken as string);
|
user = await authenticateUser(supabase, authToken as string);
|
||||||
|
|
||||||
const expectedMac = user.device?.mac_address;
|
const expectedMac = user.device?.mac_address;
|
||||||
if (mac_address && mac_address !== expectedMac) {
|
if (deviceMac && deviceMac !== expectedMac) {
|
||||||
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue