added hmac auth to report route

This commit is contained in:
Danny Coates 2020-07-25 15:36:09 -07:00
parent 2f6119e2f1
commit d9cbe058ab
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
7 changed files with 39 additions and 50 deletions

View file

@ -61,7 +61,10 @@ async function fetchWithAuth(url, params, keychain) {
const result = {};
params = params || {};
const h = await keychain.authHeader();
params.headers = new Headers({ Authorization: h });
params.headers = new Headers({
Authorization: h,
'Content-Type': 'application/json'
});
const response = await fetch(url, params);
result.response = response;
result.ok = response.ok;
@ -439,15 +442,19 @@ export async function getConstants() {
throw new Error(response.status);
}
export async function reportLink(id, key, reason) {
const response = await fetch(
export async function reportLink(id, keychain, reason) {
const result = await fetchWithAuthAndRetry(
getApiUrl(`/api/report/${id}`),
post({ key, reason })
{
method: 'POST',
body: JSON.stringify({ reason })
},
keychain
);
if (response.ok) {
if (result.ok) {
return;
}
throw new Error(response.status);
throw new Error(result.response.status);
}