Board index » delphi » Web Service with HTTP Basic Authentication Scheme

Web Service with HTTP Basic Authentication Scheme


2007-03-22 09:58:23 AM
delphi223
Hi,
I need to secure my web services with HTTP BASIC Authentication Schema, this
requires a HTTP header to be added to the HTTP unsecure headers,something
like this:
-------------------------------------------------------------
GET /private/index.html HTTP/1.0
Host: localhost
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
-------------------------------------------------------------
I think that this stuff is part of WinInet and Delphi SOAP Runtime is
independent from the communication method.
How can i append this header to my SOAP calls?
Thanks in Advance!!
Jair Karim
 
 

Re:Web Service with HTTP Basic Authentication Scheme

Hello Jair,
All you have to do is handle the OnBeforePost event on the
HTTPRIO.HTTPWebNode component and use InternetSetOption. Here's an example
from a sample that talks to MapPoint (MapPoint.NET uses 'digest'
authentication - a variant of 'basic' authentication):
procedure TTestMapPointRender.HTTPRIO1HTTPWebNode1BeforePost(
const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
UserName: string;
PassWord: string;
begin
UserName := GetWSToken('MapPoint', 'UserName');
Password := GetWSToken('MapPoint', 'Password');
if not InternetSetOption(Data,
INTERNET_OPTION_USERNAME,
PChar(UserName),
Length(UserName)) then
raiseException(SysErrorMessage(GetLastError));
if not InternetSetOption(Data,
INTERNET_OPTION_PASSWORD,
PChar(Password),
Length (Password)) then
raiseException(SysErrorMessage(GetLastError));
end;
Cheers,
Bruneau.
 

Re:Web Service with HTTP Basic Authentication Scheme

Hello Bruneau,
With MapPoint.NET you can also do the following:
RenderServiceRequest := TdaHTTPRIO.Create(Self);
RenderServiceRequest.HTTPWebNode.UserName := Username;
RenderServiceRequest.HTTPWebNode.Password := Password;
Graham Harris
 

Re:Web Service with HTTP Basic Authentication Scheme

Thanks for the info. It must have been something that was added sometime
after D7. Originally the THTTPReqResp.UserName/Password were only used for
'Proxy' support. However, there were requests to have UserName/Password be
used for authentication if a 'Proxy' is not specified. I was away from SOAP
in D2005/D2006, I suspect the support was added and I was still using the
previous approach.
Thanks again!
Bruneau.
"Graham Harris" <XXXX@XXXXX.COM>writes
Quote
Hello Bruneau,

With MapPoint.NET you can also do the following:

RenderServiceRequest := TdaHTTPRIO.Create(Self);
RenderServiceRequest.HTTPWebNode.UserName := Username;
RenderServiceRequest.HTTPWebNode.Password := Password;

Graham Harris


 

Re:Web Service with HTTP Basic Authentication Scheme

Thanks!!, your help will be very useful.
Jair Karim
"Jean-Marie Babet" <XXXX@XXXXX.COM>escribi?en el mensaje de noticias
Quote
Thanks for the info. It must have been something that was added sometime
after D7. Originally the THTTPReqResp.UserName/Password were only used for
'Proxy' support. However, there were requests to have UserName/Password be
used for authentication if a 'Proxy' is not specified. I was away from
SOAP
in D2005/D2006, I suspect the support was added and I was still using the
previous approach.

Thanks again!

Bruneau.

"Graham Harris" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Hello Bruneau,
>
>With MapPoint.NET you can also do the following:
>
>RenderServiceRequest := TdaHTTPRIO.Create(Self);
>RenderServiceRequest.HTTPWebNode.UserName := Username;
>RenderServiceRequest.HTTPWebNode.Password := Password;
>
>Graham Harris
>
>