Perform Basic Access Authentication

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Perform Basic Access Authentication

Post by kolia » Sat Oct 03, 2015 6:04 pm

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
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Perform Basic Access Authentication

Post by FourthWorld » Sat Oct 03, 2015 7:52 pm

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Re: Perform Basic Access Authentication

Post by kolia » Sat Oct 03, 2015 10:57 pm

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
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

scrabbles
Posts: 25
Joined: Sat Dec 20, 2014 4:32 am

Re: Perform Basic Access Authentication

Post by scrabbles » Sun Oct 04, 2015 7:44 am

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 &
Last edited by scrabbles on Mon Oct 05, 2015 1:54 am, edited 1 time in total.

kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Re: Perform Basic Access Authentication

Post by kolia » Sun Oct 04, 2015 9:35 am

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
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Perform Basic Access Authentication

Post by FourthWorld » Sun Oct 04, 2015 3:41 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply