Note that there are some explanatory texts on larger screens.

plurals
  1. POLogging into Stack Overflow with cURL
    text
    copied!<p>I'm working on a project and I want to log into Stack Overflow via cURL.</p> <p>I use Google as my openID provider which means that I need to log into Google first via its API.</p> <p>Here is the code I have so far:</p> <pre><code>#!/bin/sh . ./params.sh #the script with $username and $password curl --silent https://www.google.com/accounts/ClientLogin \ -d Email=$username -d Passwd=$password \ -d accountType=GOOGLE \ -d source=localhost-test-1 \ -d service=lso \ -o tokens . ./tokens echo $Auth; #$Auth is correct here - I did not get a BadAuth error. endpoint="https://www.google.com/accounts/o8/id"; curl http://stackoverflow.com/users/authenticate \ -d "openid_identifier=$endpoint" \ -w %{redirect_url}&gt; ./google_url google_url=$(cat ./google_url); echo $google_url; echo; echo; echo; curl -L --silent --header "Authorization: GoogleLogin auth=$Auth" $google_url; </code></pre> <p>At this point I get a page from Google telling me that Stack Overflow wants information and I have to log in. According to <a href="http://code.google.com/apis/gdata/articles/using_cURL.html" rel="nofollow noreferrer">this page</a>, the <code>--header ... $Auth</code> part should count as a login and redirect me to Stack Overflow.</p> <p>Here is the form I get when I run this script:</p> <pre><code>&lt;form id="gaia_universallogin" action="https://www.google.com/accounts/ServiceLoginAuth?service=lso" method="post"&gt; &lt;input type="hidden" name="continue" id="continue" value="https://www.google.com/accounts/o8/ud?st=SOME_KEY" /&gt; &lt;input type="hidden" name="service" id="service" value="lso" /&gt; &lt;input type="hidden" name="dsh" id="dsh" value="SOME_NEG_NUMBER" /&gt; &lt;/form&gt; </code></pre> <p>When I try the answer below I get the following error:</p> <pre><code> Can't call method "attr" on an undefined value at - line 8. curl: (3) &lt;url&gt; malformed --&gt;&lt;/style&gt; </code></pre> <p>here is the output from <code>google2.html</code></p> <pre><code>&lt;form id="gaia_loginform" action="https://www.google.com/accounts/ServiceLoginAuth?service=lso" method="post" &gt; &lt;input type="hidden" name="continue" id="continue" value="https://www.google.com/accounts/o8/ud?st=RNADOM" /&gt; &lt;input type="hidden" name="service" id="service" value="lso" /&gt; &lt;input type="hidden" name="dsh" id="dsh" value="NEG_NUMEBER" /&gt; &lt;input type="hidden" name="GALX" value="ABCD" /&gt; &lt;input type="text" name="Email" id="Email" /&gt; &lt;input type="password" name="Passwd" id="Passwd" &gt; &lt;input type="checkbox" name="PersistentCookie" id="PersistentCookie" value="yes" &lt;input type="hidden" name='rmShown' value="1" /&gt; &lt;input type="submit" class="gaia le button" name="signIn" id="signIn" /&gt; &lt;input type="hidden" name="asts" &gt; &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload