CURL authentication

Status
Not open for further replies.

ewdpb

Member
Oct 3, 2019
151
19
18
Hi all,I am trying to use mod_curl. According to the docs basic authentication is done like this:

local auth_url = "http://username : password@mysecure_web_service.com"
local response = api:execute("curl", auth_url)


However, I do not want to send credentials in the URL. I am trying to use it like this from LUA:

local api = freeswitch.API()
local response = api:execute('curl', 'https://mydomain.com/api/v1/info --netrc-file mycredentials.txt --insecure --request GET')


The curl statement works just fine when I run it from the same box's comand line

But I keep getting an authentication error.

1577576066838.png

Can anyone please give me a hint on what the correct format is?

PD: it does not have to be curl. If you can suggest another method to do the same I would be more than happy to know about it.

Thanks!
 
Last edited:

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
Just a wild guess, could the api:execute be having difficulty accessing your .netrc file (permisions or relative path)?
 

ewdpb

Member
Oct 3, 2019
151
19
18
Just a wild guess, could the api:execute be having difficulty accessing your .netrc file (permisions or relative path)?

Hi @Adrian Fretwell , absolutely it could. How the heck do I enable some logging letting me know what the problem may be. I am sure about the file permissions but I am not so sure about the location. I have tried several locations with absolute and relative paths but since there is no indication of failure, it is just like shooting in the dark.

Thanks very much for replying!
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
I don't think there is any logging with curl other than the exit codes and whatever is written to stderr.

For specifying the password in a file, you have two options: -n/--netrc for .netrc or -K/--config <config file> to specify a config file, the default config file is .curlrc

I believe that in the case of .netrc and .curlrc files, curl only looks for these in the users home directory or the directory specified in the $HOME environment variables. I think for the .curlrc file it will also search the directory specified in $CURL_HOME.

If you can work out which user the API call is running under, then you can probably work out where the users HOME directory is. Looking at /etc/passwd may help.

You may be able export $CURL_HOME in the Freeswitch startup scripts. Of course we could be backing up the wrong tree entirely!
 

ewdpb

Member
Oct 3, 2019
151
19
18
Thank you @Adrian Fretwell ! I had no idea about the r -K/--config <config file> option. I will play with it. I'll also explore the options of following the $CURL_HOME. However, as I mentioned in the post, it all works well when I run the command from the command line regardless of the location of the netrc file (of course specifying the location with an absolute path if necessary). By the way, do you know of another suitable way to consume Web Services in within LUA/freeswitch?

Thanks!
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,498
413
83
I'm sure there are lots of ways of doing this in LUA, using the socket libraries, socket.http, for example, but I have no experience of using any of them. There are curl bindings for LUA, there is a Debian package: https://packages.debian.org/buster/lua-curl again, I have no experience.

Hopefully someone else will chip in with some more ideas for you.
 
Status
Not open for further replies.