Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   NTLM Authentication (https://www.delphipraxis.net/193799-ntlm-authentication.html)

slemke76 24. Jul 2021 19:17

AW: NTLM Authentication
 
Hallo,

der Thread ist zwar alt, bin aber bei meiner Recherche über genau dieses Thema gestolpert, da ich die gleiche Anforderung habe.
Mein "Gegenüber" ist ein Apache mit mod_auth_ntlm_winbind, der mit Firefox, Chrome, etc. sauber NTLM authentifiziert.

Ich verwende XE8 - vorweg - die mitgelieferte Indy10 Version (10.6.2.5263) funktioniert nicht, ein aktueller clone aus dem git-Repo (https://github.com/IndySockets/Indy) von heute funktioniert.

Ansonsten ist das ganze eigentlich ganz einfach - ein Stolperstein war noch die [hoInProcessAuth] Option, die gesetzt werden muss.
Und es muss TIdSSPINTLMAuthentication von Indy genutzt werden.

Edit:
Man kann im übrigen auch manuell Benutzername & Kennwort angeben (sonst wird der aktuell angemeldete Benutzer verwendet) - das geht ganz normal mit
Delphi-Quellcode:
  IdHttp.Request.Username := 'DOMAIN\USERNAME';
  IdHttp.Request.Password := 'PASSWORD';


Delphi-Quellcode:
uses
   [...]
  IdBaseComponent,
  IdGlobal, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  IdAuthentication, IdException, IdAuthenticationSSPI, IdHeaderList;

[...]

procedure TForm1.ButtonDoRequestClick(Sender: TObject);
var IdHttp: TIdHttp;
begin
  // https://stackoverflow.com/questions/32075389/indy-https-get-authentication
  // https://github.com/IndySockets/OpenSSL-Binaries
  // https://stackoverflow.com/questions/12056951/401-with-indy-idhttp-digest-authentication-in-delphi-xe

  // Version bundled with XE8: 10.6.2.5263                                -> not working against Apache with mod_auth_ntlm_winbind
  // git checkout c7d5e086adeeb63c4db0d41c2791085bec9e1e27 / 2021-07-13   -> working

  IdHttp := TIdHttp.Create(nil);

  IdHttp.Request.Clear;
  IdHttp.Request.BasicAuthentication := false;
  IdHttp.HTTPOptions := idHttp.HTTPOptions + [hoInProcessAuth];  // WICHTIG!
  IdHttp.OnSelectAuthorization := IdHTTPSelectAuthorization;

  MemoHttpGetResult.Lines.Clear;
  try
    try
      MemoHttpGetResult.Lines.Add(IdHttp.Get('http://testserver.example.org/ntlm/'));
    except
      // see also
      // https://stackoverflow.com/questions/13950676/how-to-check-url-with-idhttp
      on E: EIdException do begin
        MemoHttpGetResult.Lines.Add('Indy raised an exception!');
        MemoHttpGetResult.Lines.Add('Exception class: ' + E.ClassName);
        MemoHttpGetResult.Lines.Add('Error message: ' + E.Message);
      end;
    else
      MemoHttpGetResult.Lines.Add('An exception occured!');
    end;
  finally
    IdHttp.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // in git checkouts of master branch BuildVersion is always 0
  LabelIndyVersion.Caption:=IntToStr(gsIdVersionMajor) + '.' +
    IntToStr(gsIdVersionMinor) + '.' +
    IntToStr(gsIdVersionRelease) + '.' +
    IntToStr(gsIdVersionBuild);
end;

procedure TForm1.IdHTTPSelectAuthorization(Sender: TObject;
  var AuthenticationClass: TIdAuthenticationClass; AuthInfo: TIdHeaderList);
begin
  AuthenticationClass := TIdSSPINTLMAuthentication;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:52 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz