我正在做一个项目,我想通过 cURL 登录 Stack Overflow。
我使用 Google 作为我的 openID 提供程序,这意味着我需要先通过其 API 登录 Google。
这是我到目前为止的代码:
#!/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;
此时我从谷歌得到一个页面,告诉我 Stack Overflow 需要信息,我必须登录。根据这个页面,这--header ... $Auth部分应该算作登录并将我重定向到 Stack Overflow。
这是我运行此脚本时得到的表单:
<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>
当我尝试下面的答案时,我收到以下错误:
Can't call method "attr" on an undefined value at - line 8.
curl: (3) <url> malformed
--></style>
这是输出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>