自从twitter废弃basic auth之后,dabr的登录就一直是个头疼的事情。虽然官方提供了数据库存储oauth access token的方案,但是这样还需要多个数据库支持…麻烦…
大家也知道,twip4是有一个模拟OAuth登录的功能的,也就是说输入用户名密码完成oauth认证。这个模拟OAuth功能是@tifan同学完成的(大家鼓掌!),稍加修改后这个oauth_proxy.php还可以通用化。以下就是将oauth_proxy.php使用于dabr实现免翻墙登录的方法。
警告:不要在任何非自己搭建的dabr上输入密码!不要在不支持https的dabr上输入自己的用户名密码!(理论上说,没有使用https,GFW可以抓到你的twitter用户名密码)
以下操作假设你已经有一个搭建好的可用的dabr站点,如果没有,请先参考官方wiki搭建好。假设这个站点是 http://example.com/dabr/
下载文件
免翻墙dabr需要从twip项目里取到以下文件:oauth_proxy.php、simple_html_dom.php
下载路径是
http://twip.googlecode.com/svn/trunk/oauth_proxy.php http://twip.googlecode.com/svn/trunk/include/simple_html_dom.php
将这两个文件放在dabr的根目录里,也就是
http://example.com/dabr/oauth_proxy.php http://example.com/dabr/simple_html_dom.php
修改文件
首先要修改oauth_proxy.php里,include simple_html_dom.php的路径。将oauth_proxy.php里,开头的
include('include/simple_html_dom.php');
修改为
include('simple_html_dom.php');
然后修改common/user.php文件。找到 function user_oauth(),该函数的最后一部分是:
// redirect user to authorisation URL $authorise_url = 'http://api.twitter.com/oauth/authorize?oauth_token='.$token['oauth_token']; header("Location: $authorise_url");
修改为:
// redirect user to authorisation URL $authorise_url = 'http://api.twitter.com/oauth/authorize?oauth_token='.$token['oauth_token']; if($_POST){ header('Location: ' . BASE_URL.'oauth_proxy.php?p='.base64_encode($_POST['password']).'&u='.base64_encode($_POST['username']).'&g='.urlencode($authorise_url)); } else{ header("Location: $authorise_url"); }
最后修改登录页面的html,加入登陆表单html。仍然是common/user.php,找到function theme_login(),该函数里开头一部分是:
$content = 'blablablabla';
在该行下方添加一行:
$content .=' <p>Try the new oauth-simulate login</p> <form action="'.BASE_URL.'oauth" method="post"> <p>Username: <input type="text" name="username"/></p> <p>Password: <input type="password" name="password"/></p> <p><input type="submit" value="Login"/></p> </form>';
如果你愿意改呢,还可以继续在这个基础上改得漂亮一点,反正以我的审美…凑合了…
现在返回dabr首页,你将看到一个用户名密码输入框,输入你的twitter用户名密码后即可完成登录。

近期评论