Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:23:36+00:00 2026-05-15T03:23:36+00:00

I’m working on a project and I want to log into Stack Overflow via

  • 0

I’m working on a project and I want to log into Stack Overflow via cURL.

I use Google as my openID provider which means that I need to log into Google first via its API.

Here is the code I have so far:

#!/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}> ./google_url
google_url=$(cat ./google_url);
echo $google_url;
echo;
echo;
echo;
curl -L --silent --header "Authorization: GoogleLogin auth=$Auth" $google_url;

At this point I get a page from Google telling me that Stack Overflow wants information and I have to log in. According to this page, the --header ... $Auth part should count as a login and redirect me to Stack Overflow.

Here is the form I get when I run this script:

<form id="gaia_universallogin"
      action="https://www.google.com/accounts/ServiceLoginAuth?service=lso" method="post">
  <input type="hidden" name="continue" id="continue"
           value="https://www.google.com/accounts/o8/ud?st=SOME_KEY" />
  <input type="hidden" name="service" id="service"
           value="lso" />
  <input type="hidden" name="dsh" id="dsh"
           value="SOME_NEG_NUMBER" />
</form>

When I try the answer below I get the following error:

    Can't call method "attr" on an undefined value at - line 8.
    curl: (3) <url> malformed
--></style>

here is the output from google2.html

<form id="gaia_loginform"      
        action="https://www.google.com/accounts/ServiceLoginAuth?service=lso" method="post"                >
  <input type="hidden" name="continue" id="continue"            value="https://www.google.com/accounts/o8/ud?st=RNADOM" />
  <input type="hidden" name="service" id="service"            value="lso" />
  <input type="hidden" name="dsh" id="dsh"            value="NEG_NUMEBER" />
  <input type="hidden"              name="GALX"             value="ABCD" />
  <input type="text" name="Email"  id="Email" />
  <input type="password"   name="Passwd" id="Passwd" > 
  <input type="checkbox" name="PersistentCookie" id="PersistentCookie"    value="yes"
  <input type="hidden" name='rmShown' value="1" />
  <input type="submit" class="gaia le button" name="signIn" id="signIn"                 />
<input type="hidden" name="asts"    >
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:23:37+00:00Added an answer on May 15, 2026 at 3:23 am

    The Google login service is specific to the particular service you’re using (Google docs vs Google Analytics vs Google Maps etc). The service ode you’ve specified (lh2) is specific to Google Picasa.

    Unfortunately there doesn’t seem to be an equivalent code for OpenId (at least, not that I could find!)

    The page that you get back from Google should contain a login form. If you look at that, it should be possible to construct a curl invocation to log in; that should then redirect you back to SO (or whichever openID page you want to log in to) logged in.

    It turns out that doing this is a little tricky, because you have to parse out some of the the form fields to submit them back to Google, and because Google doesn’t send back a straight HTTP redirect, but an HTML doc with a <meta http-equiv="redirect" ...> tag. And of course you have to enable cookies. But this is all possible in a script using curl – the following works for me:

    #!/bin/bash
    
    # Utility function for parsing values out of an HTML form
    get_value()
    {
        local tagtype="$1" attrname="$2" attrvalue="$3" getattr="$4"
        perl -MHTML::TreeBuilder - "$@" <<EOF
             @args=@ARGV;
             \$h=HTML::TreeBuilder->new;
             \$h->parse_file("$htmlfile");
             while (\$#args > 0) {
                 \$h=\$h->look_down(_tag => shift @args,
                                    shift @args => shift @args);
             }
             print \$h->attr(shift @args);
    EOF
    }
    
    # Empty the cookie jar
    cj="cookiejar"
    rm -f "$cj"
    
    # Attempt to log in to SO. This will redirect to a google URL.
    endpoint="https://www.google.com/accounts/o8/id"
    
    google_url=`curl -L -s -S http://stackoverflow.com/users/authenticate \
        -d "openid_identifier=$endpoint" \
        -o /dev/null -b "$cj" -c "$cj" \
        -w %{url_effective}`
    echo $google_url
    echo
    echo
    
    # Retrieve the form from Google
    htmlfile=googleform.html
    curl -L -s -S -o "$htmlfile" -b "$cj" -c "$cj" "$google_url"
    
    # Parse out the form fields
    form_url=`get_value form id gaia_loginform action`
    
    fdsh=`get_value form id gaia_loginform input name dsh value`
    fcontinue=`get_value form id gaia_loginform input name continue value`
    fservice=`get_value form id gaia_loginform input name service value`
    fGALX=`get_value form id gaia_loginform input name GALX value`
    frmShown=`get_value form id gaia_loginform input name rmShown value`
    fsignIn=`get_value form id gaia_loginform input name signIn value`
    
    fEmail='INSERT LOGIN EMAIL HERE'
    fPasswd='INSERT PASSWORD HERE'
    
    # Submit the login form
    htmlfile=google2.html
    curl -L -s -S -o "$htmlfile" -b "$cj" -c "$cj" --data-urlencode dsh="$fdsh" \
      --data-urlencode continue="$fcontinue" \
      --data-urlencode service="$fservice" \
      --data-urlencode GALX="$fGALX" \
      --data-urlencode Email="$fEmail" \
      --data-urlencode Passwd="$fPasswd" \
      --data-urlencode rmShown="$frmShown" \
      --data-urlencode signIn="$fsignIn" \
      "$form_url"
    
    # Interpret the redirect
    redirect=`get_value meta http-equiv refresh content | sed "s/^.*'\(.*\)'.*$/\1/"`
    
    # Follow it
    htmlfile=google3.html
    curl -L -s -S -o "$htmlfile" -b "$cj" -c "$cj" "$redirect"
    

    (Note that I seem to have a slightly different version of curl from you, so I had to change the -w options slightly; I’m guessing my version will work for you but you may need to tweak it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.