Recent

Author Topic: WST authentication in a request header  (Read 3679 times)

artix

  • Newbie
  • Posts: 1
WST authentication in a request header
« on: November 06, 2014, 08:57:20 pm »
I'm trying to get a response from a webapi server https://tt.poczta-polska.pl/Sledzenie/services/Sledzenie?wsdl
I am using Web Service Tools (WST) and I was following http://forum.lazarus.freepascal.org/index.php/topic,20064.msg116160.html#msg116160 but there is a problem. To send a correct request I need to put in a header authentication parameters like username and password.

According to the documentation in my requests there should be such a header:
Code: [Select]
<soapenv:Header>
<wsse:Security
soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>sledzeniepp</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PPSA</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>

But how can I add/change a header in a request?

My program: (sending name 'Artur' and in a response should be "Witaj Artur")
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  SYNAPSE_RegisterHTTP_Transport();
end;

procedure TForm1.Button1Click(Sender: TObject);
var Client    : SledzeniePortType  ; // connection
    witajparam: witaj_type;
    myResult: witajResponse;
begin
  Client    := wst_CreateInstance_SledzeniePortType() ;
  witajparam := witaj_type.Create() ;
  witajparam.imie:='Artur';
  myresult:=Client.witaj(witajparam);
  memo1.Lines.Add(myresult.return);
end;                               
« Last Edit: November 06, 2014, 09:18:33 pm by artix »

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: WST authentication in a request header
« Reply #1 on: January 25, 2022, 11:01:58 am »
For Basic HTTP Authentification in the file synapse_http_protocol.pas change the constuctor THTTPTransport.Create
Code: Pascal  [Select][+][-]
  1. constructor THTTPTransport.Create();
  2. begin
  3.   inherited Create();
  4.   FConnection := THTTPSend.Create();
  5.   FConnection.Protocol := '1.1';
  6.   FConnection.UserName := <your user name>;
  7.   FConnection.Password := <your password>;
  8. end;      
  9.  
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: WST authentication in a request header
« Reply #2 on: January 25, 2022, 01:57:19 pm »
1.1? Really? Should be - at least - 1.3. Current protocols allow to fall back to 1.1, but select preferred first.
« Last Edit: January 25, 2022, 02:02:06 pm by Thaddy »
Specialize a type, not a var.

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: WST authentication in a request header
« Reply #3 on: January 25, 2022, 06:05:39 pm »
First three lines between begin...end are from original code, which I installed to Lazarus through OPM. I added two last lines
Code: Pascal  [Select][+][-]
  1.   FConnection.UserName := <your user name>;
  2.   FConnection.Password := <your password>;
  3.  

In the documentation author mention, that connection through proxy server is supported by the adding additional parameters to Address string:
https://wiki.freepascal.org/Web_Service_Toolkit#HTTP_Proxy_Parameters.
I try to find out the place in the code, where this string is parsed to set ProxyServer, ProxyPort, ProxyUsername, ProxyPassword parameters for the connection and add my keys UserName and Password to set Basic HTTP Authentification parameters for the connection, but I'm failed and I added two lines to the constructor THTTPTransport.Create().





Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

 

TinyPortal © 2005-2018