To enable HTTP Basic authentication on image and information endpoints, set the following configuration keys:
Authorization
A custom delegate method can be used to implement authorization logic ranging from simple to complex. The method will be invoked upon every image request. Depending on its return value, it can either:
Authorize the request (by returning HTTP 200 OK);
Forbid the request (by returning HTTP 403 Forbidden); or
Redirect to a different URL via a response code returned from the method.
The delegate method is named authorized?(). A skeleton with documented parameters and return values is present in the delegates.rb.sample file. By default, it just returns true, authorizing all requests.
Notes
The authorization method will be called on every image request and should therefore be written to be efficient.
The authorization method will be called upon requests to all image endpoints, but not information endpoints.
Implementations should assume that the underlying source image exists, even though it may not. The image server will check for existence, but the check may occur after the delegate method is invoked.
Note: The parameters passed to authorized? are not guaranteed to be safe. identifier, for example, will be exactly as the application receives it. Prefer prepared statements over string concatenation in order to reduce vulnerability to injection attacks.
Allow only JPEG output
Allow only certain user agents
This is not foolproof—if a client knows what User-Agent you are checking for, they can spoof it.
Allow only requests that supply a valid token in a header
Restrict a region of an image
In this example, requests for images containing any part of the bottom right quadrant of the source image will be denied.