[Xml-compile] Basic authorisation

Kieron Johnson ao7one at gmail.com
Mon Dec 9 08:32:47 GMT 2013


Thanks Mark. I couldn't see that in the docs though it's quite clearly
documented! Did noticed the docs say to use "hook =3D>" but it looks like it
should be "transport_hook =3D>"

I achieved what I wanted with below code. Very straightforward thanks.

# Compile request method from WSDL

# Hook in sub for Authorization header

my $call =3D $wsdl->compileClient( $method, transport_hook =3D>
\&transport_hook );



...

...


# Transport hook for complieClient to add to http headers

# for the basic http authentication

#

# HTTP basic authentication encodes the username and password

# with Base64. The encoded source string is in the format:

#

# "username:password"

#

# With the below HTTP header being required:

#

# "Authorization: Basic [encoded password]"

#

sub transport_hook($$)

{

    my ($request, $trace) =3D @_;

    my $content =3D $request->content;



    my $user =3D 'myuserid' ;

    my $password =3D 'mypassword';



    # Encode userid and password

    my $authorization =3D 'Basic '.encode_base64( "$user:$password" );



    print "Authorization: $authorization";



    # Modify http header to include basic authorisation

    #

    $request->header(Authorization =3D> $authorization );



    my $ua =3D $trace->{user_agent};

    my $response =3D $ua->request($request);



    # ... check the response headers

    $response->header('Authorization');



    # ... use the response content

    my $received =3D $response->decoded_content || $response->content;



    $response;

}


On Wed, Dec 4, 2013 at 12:24 PM, Mark Overmeer <solutions at overmeer.net>wrot=
e:

> * Kieron Johnson (ao7one at gmail.com) [131204 11:49]:
> > I'm struggling to see how to perform basic authorisation on a Soap call
> > with xml compile. I've looked at WSS thinking basic authentication was
> the
> > same thing and it seems it isn't.
>
> SOAP has its own way of point-to-point basic authentication, see
> XML::Compile::WSS::BasicAuth.  That info is inside the XML message.
> SOAP is not limited to HTTP...
>
> To play with HTTP headers, you need to use the transport_hook.
> Read the DETAILS in XML::Compile::Transport
> --
> Regards,
>                MarkOv
>
> ------------------------------------------------------------------------
>        Mark Overmeer MSc                                MARKOV Solutions
>        Mark at Overmeer.net                          solutions at overmeer.net
> http://Mark.Overmeer.net                   http://solutions.overmeer.net
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20131209/5f=
4182c4/attachment.htm


More information about the Xml-compile mailing list