lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


	Hi Laurent

But now ... I'm blocked : my webservices are password protected and I
duno how to pass http authentication thru soap.call().
	I am not sure but I think the authentication information should be
sent through HTTP headers, thus you cannot do it with soap.client.call(),
since it sends a fixed set of headers, unfortunatelly.

But how can I do that in LUA ?
	I'll have to change soap.client.call() :-)

About WSDL, I think I can live w/o it providing I'll have to give manually
arguments' type. After being able to communicate with my webservices,
I'll check if I can do something smarter ;D
	For now you can try patching soap.client.call() to send the
appropriate headers.  LuaSocket provides functions to deal with base64
encoding.  Follows a suggestion:

-- Untested code!
local function call(args)
	...
	local request_sink, tbody = ltn12.sink.table()
	local headers = {                         -- added lines start here !
		["Content-Type"] = content_type_header,
		["content-length"] = tostring(request_body:len()),
		["SOAPAction"] = soap_action,
	}
	if args.headers then
		for key, val in pairs (args.heders) do
			headers[key] = val
		end
	end                                         -- added lines end here !
	local url = {
		...
		headers = headers,                      -- also change this line!
	}
	...
end
-- End of untested code!

	This way you can pass to soap.client.call() whatever headers
you want and also override the default ones.  But I think you'll have
to encode the login and password.  According to Wikipedia example
(http://en.wikipedia.org/wiki/Basic_access_authentication#Example)
and LuaSockets' documentation for http.request()
(http://w3.impa.br/~diego/software/luasocket/http.html#request), you'll
have to encode the login, a colon and the password, and give it preceeded
by the string "Basic " as the parameter of Authentication header.
I think the following lines will make it work:

-- Untested code!
local mime = require"mime"
local client = require"soap.client"

client.call {
	headers = {
		Authorization = "Basic "..mime.b64 (login..':'..password),
	},
	... -- add your arguments
}
-- End of untested code!

	It seems there is a mistype in LuaSocket's docs; it
says the header name is "authentication", while the RFC 2068
(http://www.ietf.org/rfc/rfc2068.txt) only mentions "authorization".
	Please, tell me if it works.  I'll be glad to improve LuaSOAP
this way.

	Regards,
		Tomás