first basic auth
This commit is contained in:
parent
62847f569d
commit
4896c63b1a
@ -4,6 +4,7 @@ DB_PASSWORD=""
|
|||||||
DB_HOST=""
|
DB_HOST=""
|
||||||
DB_DIALECT=""
|
DB_DIALECT=""
|
||||||
DB_PORT=""
|
DB_PORT=""
|
||||||
|
WEBHOOK_TOKEN="" #Token that is placed a the TTN Webhook auth
|
||||||
WIGLE_TOKEN="" # Go to account and generate token "Encoded for use"
|
WIGLE_TOKEN="" # Go to account and generate token "Encoded for use"
|
||||||
WIGLE_BASE_URL="https://api.wigle.net"
|
WIGLE_BASE_URL="https://api.wigle.net"
|
||||||
WIGLE_NETWORK_SEARCH="/api/v2/network/search"
|
WIGLE_NETWORK_SEARCH="/api/v2/network/search"
|
||||||
|
@ -9,9 +9,16 @@ import json
|
|||||||
import argparse
|
import argparse
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
token = "ich-bin-da-token"
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {token}",
|
||||||
|
"Content-Type": "application/json", # Adjust if needed for your payload format
|
||||||
|
}
|
||||||
|
|
||||||
def send_post_request(uri, data):
|
def send_post_request(uri, data):
|
||||||
try:
|
try:
|
||||||
requests.post(uri, json=data, timeout=1)
|
requests.post(uri, json=data, timeout=1, headers=headers)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -24,6 +24,36 @@ router.post(
|
|||||||
"/webhook",
|
"/webhook",
|
||||||
validateData(ttnMessageValidator),
|
validateData(ttnMessageValidator),
|
||||||
async (req: Request, res: Response) => {
|
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 {
|
try {
|
||||||
const message = req.body as TtnMessage;
|
const message = req.body as TtnMessage;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user