I’ve been stuck with this issue, you see…
I’ve a collection on wix, i can access it with http requests from an app made with python, everything works as intented BUT I am implementing some basic security, I’ using hmac authentication for the requests but i alway get the 400 error with the message of invalid token, the one that comes from the catch message of the function on the http-functions.js file.
Here it is how it is coded on the server side.
import {ok, notFound, serverError, created, badRequest} from 'wix-http-functions';
import { validateAuth } from "@velo/wix-http-functions-hmac-authentication-backend";
import wixData from 'wix-data';
const defaultResponse = {
headers: {
"Content-Type": "application/json"
}
};
const defaultInvalidAuthResponse = {
...defaultResponse,
body: {
error: "Invalid authentication token"
}
}
export async function get_MyCollection(request){
try {
await validateAuth(request, { secretName: "MySecret" });
}
catch (err) {
return badRequest(defaultInvalidAuthResponse);
}
}
Now this is how it is coded on the client app, an app installed locally on the pc of the client.
import requests
import json
import hmac
import hashlib
import base64
def readMyCollection():
secret_key = 'MySecret'
message = 'GET'
signature = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).digest()
signature_base64 = base64.b64encode(signature).decode()
headers = {
'Authorization': f'HMAC {signature_base64}',
'Content-Type': 'application/json'
}
print(signature_base64)
response = requests.get(MyServerURL, headers=headers)
if response.status_code == 200:
print("GET request successful")
data = response.json()
print(data)
print("Data obtention successfull!!!")
else:
print(f"GET request failed with status code {response.status_code}")
print(response.json())
return
On the wix site, everything is setup, the secret, the http-functions.js file, everything works before adding the authetication code, but i dont know why is giving the error:
GET request failed with status code 400
{'error': 'Invalid authentication token'}
Please, any help is much appreciated.