PDA

View Full Version : "inject" cookie to external browser



dotjan
15th November 2012, 00:52
Hi, with my app the user gets authenticated to a website where he gets cookies for the session. Then I would need the user to navigate through an external browser (i.e. firefox) and appear as already authenticated. So I basically need to pass the cookies from my cookiejar to firefox.

Does anyone have experience with this? I know it is more related to firefox but I wonder if there is a hint from the experts here as well.

Thanks,
Jan

wysota
15th November 2012, 06:38
I think it all depends whether firefox is already active or not. If not, you can access its cookie database (it's in sqlite format) and inject the cookie there. If firefox is already active then... well... you're probably out of luck. What is the point of what you are trying to do? Can't you do it without the external browser or by forwarding auth information in the url passed to the browser?

dotjan
15th November 2012, 10:08
Hi wysota,

I see, so your thought is that the database is read only at startup.. this may be a problem also because it seems firefox -new-instance seems cannot be created, at least by default (I have to double check).

My app is actually currently using a QWebView object in order to let the user browse the content, however i really think that using the user's default and preferred browser would be the best if I could still keep and so automate the initial authentication steps in my app..

Authentication could be made with a properly formatted URL of course, this is the way I would go in case there are no other options. The problem with this solution is that either I open a firefox new tab/windows at the very beginning of my app to authenticate the user or I always go for authentication process (not fast at all) every time the user need to browse some content. The former would mean there will always be a firefox session open with my app and if closed nothing will work anymore, not good, the latter would solve this issue and results more elegant but much more slow.. not the best...

So this is why I think the top would be "silently" authenticate the user using a QWebPage and collecting all the cookies for the session, as I do now, and then pass this information somehow to the external browser.. Just realized I mentioned firefox but could be any other browser... even more complicated... :-(

Thanks,
Jan

Added after 5 minutes:


this may be a problem also because it seems firefox -new-instance seems cannot be created, at least by default (I have to double check).

Just verified -new-instance is intended to work with a profile different than the current one...

wysota
15th November 2012, 10:49
I don't think you can find a general solution to your problem. Injecting a cookie in popular browsers shouldn't be that much of a problem provided they are not running but one can always have a custom browser or the browser might already be running. Going with the QWebView approach is probably the easiest thing to do.

dotjan
15th November 2012, 12:07
yes I think you are right wysota. Have also a discussion with firefox dev and accessing sqlite db while firefox is running will cause issue and it actually ties me to it which could change in the future. And anyway it also true I will tie myself to firefox only which is not what I want.

i will have to make my QWebView more similar to a browser, actually not really evertything.

Thanks,
Jan