Page 1 of 1
Parse user authentication
Posted: Sun May 03, 2015 9:43 pm
by pink
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
Re: Parse user authentication
Posted: Mon May 04, 2015 11:24 am
by robl
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
Re: Parse user authentication
Posted: Mon May 04, 2015 2:52 pm
by pink
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"
Re: Parse user authentication
Posted: Mon May 04, 2015 4:58 pm
by robl
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.