use custom user agent header

This commit is contained in:
Martin McKeaveney 2020-06-03 19:35:04 +01:00
parent 6a8090f69b
commit 94731e017a
2 changed files with 6 additions and 9 deletions

View File

@ -3,7 +3,7 @@ const apiCall = method => async (url, body) => {
method: method, method: method,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": "Budibase Builder", "x-user-agent": "Budibase Builder",
}, },
body: body && JSON.stringify(body), body: body && JSON.stringify(body),
}) })

View File

@ -15,19 +15,16 @@ module.exports = async (ctx, next) => {
const appToken = ctx.cookies.get("budibase:token") const appToken = ctx.cookies.get("budibase:token")
const builderToken = ctx.cookies.get("builder:token") const builderToken = ctx.cookies.get("builder:token")
const isBuilderAgent = ctx.headers["user-agent"] === "Budibase Builder" const isBuilderAgent = ctx.headers["x-user-agent"] === "Budibase Builder"
// all admin api access should auth with buildertoken and 'Budibase Builder user agent // all admin api access should auth with buildertoken and 'Budibase Builder user agent
const shouldAuthAsBuilder = isBuilderAgent && builderToken const shouldAuthAsBuilder = isBuilderAgent && builderToken
if (shouldAuthAsBuilder) { if (shouldAuthAsBuilder) {
if (builderToken === env.ADMIN_SECRET) { const builderTokenValid = builderToken === env.ADMIN_SECRET
ctx.isAuthenticated = true
ctx.isBuilder = true ctx.isAuthenticated = builderTokenValid
} else { ctx.isBuilder = builderTokenValid
ctx.isAuthenticated = false
ctx.isBuilder = false
}
await next() await next()
return return