You are not logged in.
Pages: 1
Would it be possible to add credentials support in TWinHTTP?
I hacked it by overriding InternalSendRequest, but it could probably be standardized.
Below are the relevant snippets to be adapted (could not test NTLM, and PASSPORT did not seem to work, but I did not try very hard).
For Windows servers, the strongest one is NEGOTIATE (secure, domain-level authentication)
type
TdwsWinHTTP = class (TWinHTTP)
FAuthScheme : TWebRequestAuthentication;
FUserName : String;
FPassword : String;
procedure InternalSendRequest(const aData: RawByteString); override;
end;
function WinHttpSetCredentials(hRequest: HINTERNET;
AuthTargets: DWORD; AuthScheme: DWORD;
pwszUserName: PWideChar; pwszPassword: PWideChar;
pAuthParams: Pointer) : BOOL; stdcall; external 'winhttp.dll';
const
WINHTTP_AUTH_TARGET_SERVER = 0;
WINHTTP_AUTH_TARGET_PROXY = 1;
WINHTTP_AUTH_SCHEME_BASIC = $00000001;
WINHTTP_AUTH_SCHEME_NTLM = $00000002;
WINHTTP_AUTH_SCHEME_PASSPORT = $00000004;
WINHTTP_AUTH_SCHEME_DIGEST = $00000008;
WINHTTP_AUTH_SCHEME_NEGOTIATE = $00000010;
procedure TdwsWinHTTP.InternalSendRequest(const aData: RawByteString);
var
winAuth : DWORD;
begin
if FAuthScheme<>wraNone then begin
case FAuthScheme of
wraBasic : winAuth := WINHTTP_AUTH_SCHEME_BASIC;
wraDigest : winAuth := WINHTTP_AUTH_SCHEME_DIGEST;
wraNegotiate : winAuth := WINHTTP_AUTH_SCHEME_NEGOTIATE;
else
raise EWinHTTP.CreateFmt('Unsupported request authentication scheme (%d)',
[Ord(FAuthScheme)]);
end;
if not WinHttpSetCredentials(fRequest, WINHTTP_AUTH_TARGET_SERVER,
winAuth, PChar(FUserName), PChar(FPassword), nil) then
RaiseLastOSError;
end;
inherited InternalSendRequest(aData);
end;
Offline
Good idea.
See http://synopse.info/fossil/info/7310be28cd
I've also added the corresponding new properties for our TSQLHttpClientWinHTTP REST class.
Thanks for the feedback!
Offline
Pages: 1