first basic auth
This commit is contained in:
@ -24,6 +24,36 @@ router.post(
|
||||
"/webhook",
|
||||
validateData(ttnMessageValidator),
|
||||
async (req: Request, res: Response) => {
|
||||
try {
|
||||
const authorizationHeader = req.headers['authorization'];
|
||||
if (!authorizationHeader) {
|
||||
console.log("Authorization header is missing!");
|
||||
res.status(401).json({ error: "Authentication failed" });
|
||||
return;
|
||||
} else {
|
||||
const token = authorizationHeader.split(' ')[1]; // Get the token after 'Bearer'
|
||||
if (!token) {
|
||||
console.log("Bearer token is missing!");
|
||||
res.status(401).json({ error: "Authentication failed" });
|
||||
return;
|
||||
}
|
||||
else {
|
||||
console.log(token)
|
||||
if (token !== process.env.WEBHOOK_TOKEN) {
|
||||
console.log("Bearer token is wrong!");
|
||||
res.status(401).json({ error: "Authentication failed" });
|
||||
return;
|
||||
} else {
|
||||
console.log("Bearer token is correct!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(401).json({ error: "Authentication failed" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const message = req.body as TtnMessage;
|
||||
|
||||
@ -96,9 +126,9 @@ router.post(
|
||||
gnss:
|
||||
gnnsLocation.latitude && gnnsLocation.longitude
|
||||
? {
|
||||
latitude: gnnsLocation.latitude,
|
||||
longitude: gnnsLocation.longitude,
|
||||
}
|
||||
latitude: gnnsLocation.latitude,
|
||||
longitude: gnnsLocation.longitude,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user