Parse user authentication

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Parse user authentication

Post by pink » Sun May 03, 2015 9:43 pm

I've had no problem creating users on Parse (all you need to do is post data), but I'm stuck on this part.

Below is the CURL example they provide for logging in, I'm not sure how to get the username and password parts into a livcode script... any ideas?

Code: Select all

curl -X GET \ 
  -H "X-Parse-Application-Id: kMHGwB2beTg1AQCp93GtbBGVsmy0ig8HOqpn3n0X" \ 
  -H "X-Parse-REST-API-Key: de2LgYYdoVLLrdkjMv0NcTphReRJc871cR3y5uk4" \ 
  -H "X-Parse-Revocable-Session: 1" \ 
  -G \ 
  --data-urlencode 'username=cooldude6' \ 
  --data-urlencode 'password=p_n7!-e8' \ 
  https://api.parse.com/1/login
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

robl
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Wed Dec 22, 2010 9:50 pm
Location: 3rd planet from the Sun

Re: Parse user authentication

Post by robl » Mon May 04, 2015 11:24 am

Hi, Greg.

According to your CURL example, it looks like they are using an HTTP GET, not a POST. (Otherwise, it would have started with "curl -X POST".)

Below should be the LiveCode equivalent for the CURL example you provided.

Code: Select all

-- add the HTTP headers
put "X-Parse-Application-Id: kMHGwB2beTg1AQCp93GtbBGVsmy0ig8HOqpn3n0X" & CRLF into tHeaders
put "X-Parse-REST-API-Key: de2LgYYdoVLLrdkjMv0NcTphReRJc871cR3y5uk4" & CRLF after tHeaders
put "X-Parse-Revocable-Session: 1" after tHeaders
set the httpHeaders to tHeaders

-- encode the params
put urlEncode("username=cooldude6") & "&" & urlEncode("password=p_n7!-e8") into tParams

--send to Parse and get the results
put URL "https://api.parse.com/1/login?" & tParams into tResults

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: Parse user authentication

Post by pink » Mon May 04, 2015 2:52 pm

Thanks, it almost worked. I had to make a couple of tweaks. As-is I got the error below:

{"code":201,"error":"missing user password"}
username%3Dcooldude6&password%3Dp_n7%21-e8

I changed it so that only the username and password get urlEncoded, and the "=" stays as is, this returns the login token that I needed!
Thanks again for getting me on the right path

Code: Select all

     -- encode the params
     put urlEncode("cooldude6") into tUsername
     put urlEncode("p_n7!-e8") into tPassword
     
     --send to Parse and get the results
     put "https://api.parse.com/1/login?username=" & tUsername & "&password="&tPassword into loginURL
     put URL loginURL into tResults
     put tResults into field "Field"
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

robl
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Wed Dec 22, 2010 9:50 pm
Location: 3rd planet from the Sun

Re: Parse user authentication

Post by robl » Mon May 04, 2015 4:58 pm

Greg:

Good catch! I should have caught that myself, but I replied before my second cup of coffee in the morning. You are right, the urlEncode was "encoding" the = symbol, which is incorrect.

I am glad you got it working.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”