views:

221

answers:

2

Is it possible to do part of a web flow in Perl and then transfer the rest of the session to Firefox?
I need to retry(with Perl) logging in to a website which returns 500 every now and then on a successful login, transfer the authenticated session to Firefox, from where I can continue my normal browsing. Is this possible?
If this is possible, how do I do it? Can you point me to some resources on how can transfer the cookie/session, etc ?

+1  A: 

Tricky. You will not be able to have your server log in to the 3rd party service, and then just serve up the session cookie to your user, and redirect him to the 3rd party app. This will not work because cookies are domain specific, and domains cannot access cookies from or set by another domain.

So your service will need to act as an interface to the third party service, and as such you will need to maintain a user session on your server. This user session keeps track of your user, will log in to third party service, and will make requests to the 3rd party service when appropriate. The session on your server will be an http client for this 3rd party service, so it will need to be able to handle cookies correctly - ie mimic a browser.

In terms of setting up and maintaining user sessions, there will be a number of CPAN modules to help you with this.

For more info on managing user sessions in Perl, see http://articles.techrepublic.com.com/5100-10878_11-1044683.html

Edit: some web services can manage user sessions by injecting a session id into the URL when the client refuses cookies. If your 3rd party service will do this, you could maybe just serve up the login response URL as a redirect to your user. However, this will break if sessions are bound to an IP.

Richard
Why do you say you can't do this? Your Perl script uses the Firefox cookies file, saves any new cookies it gets to the same cookies file, then restarts Firefox, which then uses the same cookies file. I do this sometimes, which is why I'm the guy who wrote a lot of the HTTP::Cookies modules.
brian d foy
@brian: i may have misunderstood the question. I thought he was talking about a web service that logged into some other service, transferring the session to his user.
Richard
+5  A: 

To me, it seems that it makes more sense to do everything from within Firefox ... and control that from the outside. MozRepl (the FF extension) and MozRepl (the Perl module) may help you in getting there.

hillu