Search Unity

help request: Using www to log in to rails site over https [solved]

Discussion in 'Scripting' started by DuncanR, Nov 26, 2014.

  1. DuncanR

    DuncanR

    Joined:
    Dec 18, 2013
    Posts:
    9
    I am sorry if this has been answered somewhere, I have read dozens of threads and unity answers and I am still stuck.

    I am trying to automate some tasks at work for which I have to use a website. This is a virtual machine running an instance of Tarantula. My login script can be found here. It is very messy I know it is the result of a lot of experimentation in things I don't understand. The GetExecutions() function should return a list of executions provided by the site in JSON format. I have built this based on my observation of what information my browser is sending and requesting, read with firebug.

    The isConnected() function (yes I just noticed, capitalisation style breach :-() and the GetExecutions() function are called repeatedly until they respond with something usable.

    The script calls the login page with a simple GET, then retrieves the athorisation code and the session cookie from the resulting html and headers. It then sends both of these with the user's given login and password as a POST to the same URL. This results in a redirect. This redirect is the most likely cause of my failure. I was assuming that as the redirect is to the user interface part of the site however that this means it is a successful login and the session is active. When I request the executions JSON however I get a reply containing the login page again. This is what happens in a browser if you are not logged in when you ask for the JSON.

    Basically as far as I can tell I a authenticating correctly with the server but I am not getting logged in. Can anyone see any obvious mistakes or tell me a bit more about how the system should work?
     
  2. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    Does the redirect include any other information in the headers? After you log in, the next result (redirect in this case) will probably have a user token or a different session id. If you still try to use the pre-auth token and/or session, the server has no idea that you're the one that just logged in.
     
  3. DuncanR

    DuncanR

    Joined:
    Dec 18, 2013
    Posts:
    9
    Thank you sir, you have made my day. There was simply a new cookie set after login. I should have checked for that but my brain was fried after resolving the first 30 or so issues with my script :)