Require an API Key for Squiz Matrix Sites

Tue, Jul. 23, 2013

I recently needed to build an API for a mobile app and was going to use Squiz Matrix. The API wasn't really private, but we wanted to restrict it enough that you needed to have an API Key in order to access it. This provided to be quite easy in Matrix using a show_if design area in the Design Parse File.

<MySource_PRINT id_name="__global__" var="content_type" content_type="text/xml; charset=utf-8" />
<MySource_area id_name="body" design_area="body" print="no" />
<MySource_AREA id_name="showContentIfKey" design_area="show_if">
<MySource_SET name="condition" value="keyword_regexp"/>
<MySource_SET name="condition_keyword" value="globals_get_key" />
<MySource_SET name="condition_keyword_match" value="123456" />
        <MySource_print id_name="body" />
    <?xml version="1.0" encoding="UTF-8"?>
        <error code="1">API Key Missing. Please enter a valid API Key.</error>

Now when you apply the design to an asset, that asset can only be viewed with the ?key=123456 query string added to the end of the URL.

Nicholas Hubbard


Justin AVery
Nov 6, 2013
That's a brilliant idea Nic, I'm doing more and more of these for some internal resources and this never really occurred to me.

Add Comment