Page 1 of 1

How to user PHP cUrl to login to a Twitter oAuth site?

Posted: Sun Apr 11, 2010 12:12 pm
by SeriousSamP
Hi,
I am trying to use php cUrl to execute a php file on a website that requires login using Twitter oAuth. Some of may be familiar with this service. The website generates a oauth token and sends it to Twitter, who then ask you to allow the application. When you do you are then sent to the applications callback.php with the token being sent again. This then gives you a cookie called PHPSESSID that keeps you logged in. I am having some trouble with this though. In order to get the cookie with cUrl I have to do the rest. I have started by loading the main page of the site into a DOM object and extracting the Twitter oauth url. I then curl to that url but cannot work out how to parse the login details. The form on that page has the action set to that page and I have tried manually creating a url using that and all the inputs in the form but I just end up back there. So how can I do this???

I am sure there are a reasonable number of situations where this could be useful. Maybe someone has done it already? If not it would be good to know anyway. Thanks for any help,
Sam.

ps. Please tell me if you need any code posted.

Re: How to user PHP cUrl to login to a Twitter oAuth site?

Posted: Mon Apr 12, 2010 3:58 am
by SeriousSamP
BUMP

sorry I do not usually like to bump my threads but I am working on a tight schedule on this project and would really appreciate some help. Even if you just say it's impossible because then I know.

Thanks,
Sam.

Re: How to user PHP cUrl to login to a Twitter oAuth site?

Posted: Mon Apr 12, 2010 4:59 am
by marty pain
I'm not massively hot on this, but have been reading a bit about cURL recently. The auth information may be returned in the header of the return value after using cURL on the twitter URL. In order to use this, you have to set cURL to use modified headers. Check in the manual for info on how. Whilst you are there, check to see if there are any specific AUTH settings you could use as that rings a bell too. Let us know how you get on.

Re: How to user PHP cUrl to login to a Twitter oAuth site?

Posted: Mon Apr 12, 2010 5:48 am
by SeriousSamP
Thanks, I will take a break from writing my analysis of the new Doctor Who, I know, geeky, and take a look at this. I had a long go trying to work this out a day or so ago using Wireshark to see what is sent by what and I think the cookie information is set by the callback.php on the site. My main trouble at the moment seems to be submitting the Twitter form that then calls the callback page. For some reason I cannot seem to be able to submit the form, or atleast when I do I end up back at the form page with no sign of anythhing having happened and the callback page does not allow the app after that so it's not submitting. I have tried this both manually constructing the url from the inputs in the HTML and had a little go using cUrl post. I have not come accross a oauth system built into cUrl but if it exists that would be brilliant.

Thanks for the reply i'l let you know how I get on.

Sam.

Re: How to user PHP cUrl to login to a Twitter oAuth site?

Posted: Mon Apr 12, 2010 5:59 am
by SeriousSamP
There is no native oauth support in cUrl.