Digest authentication and HTTPServer

Giganews Newsgroups
Subject: Digest authentication and HTTPServer
Posted by:  Christian Elber (ebbew…@hotmail.com)
Date: Tue, 19 May 2009

Hello,

I have a problem with Digest authentication and TIdHTTPServer. I have read
in previous posts that I only need to include IdAuthenticationDigest to my
unit, but my server still uses basic authentication. I have added an
IdServerInterceptLogFile to my HttpServer so I can see the traffic, and it
looks like:

127.0.0.1:53040 Stat Connected.
127.0.0.1:53040 Recv 2009-05-19 09:36:42: GET /Test HTTP/1.1<EOL>Accept:
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-ms-application, application/vnd.ms-xpsdocument,
application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash,
*/*<EOL>Accept-Language: sv<EOL>UA-CPU: x86<EOL>Accept-Encoding: gzip,
deflate<EOL>User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;
SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30618; .NET CLR 3.5.30729)<EOL>Host:
127.0.0.1:8000<EOL>Connection: Keep-Alive<EOL><EOL>
127.0.0.1:53040 Sent 2009-05-19 09:36:42: HTTP/1.1 401
Unauthorized<EOL>Connection: close<EOL>WWW-Authenticate: Basic
realm="Test"<EOL>Content-Type: text/html<EOL><EOL>
127.0.0.1:53040 Sent 2009-05-19 09:36:42: <HTML><BODY><B>401
Unauthorized</B></BODY></HTML>
127.0.0.1:53040 Stat Disconnected.
0.0.0.0:0 Stat Disconnected.
127.0.0.1:53128 Stat Connected.
127.0.0.1:53128 Recv 2009-05-19 09:36:47: GET /Test HTTP/1.1<EOL>Accept:
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-ms-application, application/vnd.ms-xpsdocument,
application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash,
*/*<EOL>Accept-Language: sv<EOL>UA-CPU: x86<EOL>Accept-Encoding: gzip,
deflate<EOL>User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;
SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30618; .NET CLR 3.5.30729)<EOL>Host:
127.0.0.1:8000<EOL>Connection: Keep-Alive<EOL>Authorization: Basic
dGVzdDp0ZXN0<EOL><EOL>
127.0.0.1:53128 Sent 2009-05-19 09:36:47: HTTP/1.1 200 OK<EOL>Connection:
close<EOL>Content-Type: text/xml<EOL>Content-Length: 23<EOL><EOL>
127.0.0.1:53128 Sent 2009-05-19 09:36:47: <christian></christian>
127.0.0.1:53128 Stat Disconnected.
0.0.0.0:0 Stat Disconnected.

My code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer,
IdCustomHTTPServer,
  IdHTTPServer, idContext, IdIntercept,
  IdServerInterceptLogBase, IdServerInterceptLogFile;

type
  TForm1 = class(TForm)
    httpServer: TIdHTTPServer;
    IdServerInterceptLogFile1: TIdServerInterceptLogFile;
    procedure httpServerCommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses IdAuthenticationDigest;
{$R *.dfm}

procedure TForm1.httpServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  if ARequestInfo.AuthExists = false then
      begin
        AResponseInfo.AuthRealm:= 'Test';
        exit;
      end
  else
    begin
      AResponseInfo.ContentType := 'text/xml';
      AResponseInfo.ContentText := '<christian></christian>';
    end;
end;

end.

I have downloaded the latest snapshot of Indy (2009-05-18) version 10.2.3
and using Delphi 2007. I attach the little code sample I have tested with to
see if anybody can see my mistake!

//Christian

Replies