Indy HTTP Server (TIdHTTPServer) supports HTTP Basic Authentication with the properties AuthExists, AuthUser and AuthPass of the Request object and the Response.AuthRealm property. (I have not checked if NTLM or Digest auth are supported also).
By setting the AuthRealm property in the Response, the client will be notified that a Basic Authentification is required. If the client sends the username and password in the request, the server can check it in the command handler.
So actually Indy provides built-in support for securing resources - this works both with a normal browser and with a REST client, both will only be able to access server resources if the request includes the auth header.
I have implemented it also in my Indy based (commercial) web framework. The example code secures all content on the server and has a hard coded user name / password combination.
procedure TBasicAuthHandlerWrapper.Handle(Target: string; Context:
TdjServerContext;
Request: TIdHTTPRequestInfo; Response: TIdHTTPResponseInfo);
const
AUTH_USER = 'sherlock';
AUTH_PASS = 'holmes';
begin
if Request.AuthExists and ((Request.AuthUsername = AUTH_USER) and
(Request.AuthPassword = AUTH_PASS)) then
begin
// pass
inherited;
end
else
begin
// show login dialog
Response.AuthRealm := 'Welcome to Web Components Server!';
end;
end;
Note: this example protects all resources independent of extension and path. But this is easy to add in the method body, by checking conditions of the path which is available in Request.Document.