We have two applications. They call a website with SOAP protocol.
One of them asked login data in OUR login form; the other is an background process, scheduled task. Both of them use InternetSetOption to make basic auth.
If the user types wrong username or password the SOAP call will show an IE dialog to get the username / password again.
1.) It is not in our style. 2.) The dialog is "infinite", it asks, only success or cancel get out from reshowing. 3.) We can't control, how many times will appear. 4.) In the background process the dialog stops the process - this is critical.
So I need some option, or event to prevent showing of IE login dialog.
If the login name / password is wrong the program must abort with 401 without showing IE dialog infinetely.
How can I do this?
Please help with some code. Thank you!
Some pieces of the code. But I think it not helps too much. This is a simple SOAP call with basic auth. But if the login is incorrect, the IE will show his dialog.
type TWSRIO = class(THTTPRIO)
...
end;
procedure TWSRIO.OnBeforePost(const HTTPReqResp: THTTPReqResp; Data:Pointer);
begin
if Auth_Mod = SCRBRIO_Auth_Basic then
begin
if not InternetSetOption(Data,INTERNET_OPTION_USERNAME,PChar(FAuth_LoginName), Length(FAuth_LoginName)) then
raise Exception.Create(SysErrorMessage(GetLastError));
if not InternetSetOption(Data, INTERNET_OPTION_PASSWORD, PChar(FAuth_Password), Length(FAuth_Password)) then
raise Exception.Create(SysErrorMessage(GetLastError));
end;
end;
procedure TForm1.Test;
begin
RIO := TWSRIO.Create(Self);
RIO.Auth_Mode := SCRBRIO_Auth_Basic;
RIO.Auth_LoginName := xxx;
RIO.Auth_Password := yyy;
...
o := GetStockQueryResponderInterface(False, GetURL(), RIO);
o.GetStockQuery(sArtNr)
...
end;
Maybe the solution is:
function TMyRIO.MyWiniNetError(LastError: DWord; Request: Pointer): DWord;
var
OWEProc: TWinInetErrorEvent;
begin
// When the LastError is zero, we return same code what the dialog does on Cancel
if LastError = 0 then
begin
Result := ERROR_SUCCESS;
Exit;
end;
if Assigned(HTTPWebNode) then
begin
try
// Save old proc and set to nil for Avoid infinite loop
OWEProc := Self.HTTPWebNode.OnWinInetError;
Self.HTTPWebNode.OnWinInetError := nil;
try
// Call the original handler
Result := Self.HTTPWebNode.HandleWinInetError(LastError, Request, True);
finally
// Restore our handler
Self.HTTPWebNode.OnWinInetError := OWEProc;
end;
except
on E: Exception do
begin
// On error we log the problem
LogThis(E.Message);
Result := ERROR_SUCCESS;
Exit;
end;
end;
end else
begin
Result := ERROR_SUCCESS;
Exit;
end;
end;
I don't know what kind of side effects would we get. But with this code I can't get Windows login dialog on wrong auth. Just the error.