Page 1 of 1

Perform Basic Access Authentication

Posted: Sat Oct 03, 2015 6:04 pm
by kolia
Hello,

I have to perform a Basic Access Authentication against protocol specified in RFC 2617 in order to use an HTTP API. I have the feeling that I should use the httpHeaders keyword but I have no clue on how to do it. I have to send user and password to the server in order to use the API. Can someone show the path?
Thank you
Nicolas

Re: Perform Basic Access Authentication

Posted: Sat Oct 03, 2015 7:52 pm
by FourthWorld
HTTP Basic Authentication has many options for different scenarios, but the most commonly-used way for clients to provide credentials is to embed them in the URL in this form, without requiring us to make explicit header changes:

http://username@password:www.domain.com/resource

What error do you get when you try that? And are you using GET or POST?

Re: Perform Basic Access Authentication

Posted: Sat Oct 03, 2015 10:57 pm
by kolia
Thanks FourthWorld
This method I do know does not work in that case. I guess I have to send the credentials with headers instruction that I'm not familiar with. I used base64 encoding of username:password, but this does not work so far. I sniffed the http header and the credentials don't seem to be part of the stream. I use Put URL httpRequest
Nicolas

Re: Perform Basic Access Authentication

Posted: Sun Oct 04, 2015 7:44 am
by scrabbles
Hi, this is what i use and it works for me. You might have been missing the auth type of basic or missing a colon space, minor things like that can trip up things.

Code: Select all

put "https://" & myServer & "/api/xxxxxx/?q=" & urlencode(searchTerm) into myURL
put base64encode("user:password") into userpass
put "Authorization: Basic " & userpass into UserAuth
set the httpHeaders to UserAuth   
put URL myURL into myResponse
edit: changed + to &

Re: Perform Basic Access Authentication

Posted: Sun Oct 04, 2015 9:35 am
by kolia
Thanks so much scrabbles, as you said, a simple missing character was the culprit.
For info, the + sign triggers an exception, the & sign should be instead, isn'it?
Nicolas

Re: Perform Basic Access Authentication

Posted: Sun Oct 04, 2015 3:41 pm
by FourthWorld
kolia wrote:Thanks so much scrabbles, as you said, a simple missing character was the culprit.
For info, the + sign triggers an exception, the & sign should be instead, isn'it?
Yes. Had the code accompanied the first post it would have been caught by one of the regulars straightaway.