Allow the API key to be passed as an "apiKey" parameter in the query string or POST body as an alternate option to a header.

This is needed to avoid triggering a CORS preflight (which occurs when using an X-API-KEY header). The core isn't currently capable of responding to a preflight and the UI therefore blocks the entire request. See: https://stackoverflow.com/a/43881141
This commit is contained in:
CalDescent 2021-11-14 20:24:02 +00:00
parent 2f51c1bf47
commit 9c952785e6

View File

@ -36,6 +36,10 @@ public abstract class Security {
// We require an API key to be passed // We require an API key to be passed
String passedApiKey = request.getHeader(API_KEY_HEADER); String passedApiKey = request.getHeader(API_KEY_HEADER);
if (passedApiKey == null) {
// Try query string - this is needed to avoid a CORS preflight. See: https://stackoverflow.com/a/43881141
passedApiKey = request.getParameter("apiKey");
}
if (passedApiKey == null) { if (passedApiKey == null) {
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.UNAUTHORIZED, "Missing 'X-API-KEY' header"); throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.UNAUTHORIZED, "Missing 'X-API-KEY' header");
} }