的GreaseMonkey脚本来自动登录使用HTTP认证 [英] GreaseMonkey script to auto login using HTTP authentication

查看:212
本文介绍了的GreaseMonkey脚本来自动登录使用HTTP认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了相当多的Greasemonkey脚本来我在我的作品写了自动登录我到我们这里的内部网站。我已经成功地写这些网站除了我们的考勤表的应用程序,它使用HTTP认证将近每一个脚本。

I've got quite a few GreaseMonkey scripts that I wrote at my work which automatically log me into the internal sites we have here. I've managed to write a script for nearly each one of these sites except for our time sheet application, which uses HTTP authentication.

有没有一种方法,我可以使用的GreaseMonkey我登录到这个网站自动?

Is there a way I can use GreaseMonkey to log me into this site automatically?

编辑:我知道在浏览器中存储密码的功能,但是我的脚本检查,如果我登录到加载时(通过遍历HTML)的网站,然后将文章提交到登录页面走得更远了一步。这种去除了加载了该网站,进入登录页面,输入我的凭据,然后点击提交的步骤

I am aware of the store password functionality in browsers, but my scripts go a step further by checking if I'm logged into the site when it loads (by traversing HTML) and then submitting a post to the login page. This removes the step of having to load up the site, entering the login page, entering my credentials, then hitting submit

推荐答案

可以登录通过设置授权HTTP标头使用HTTP认证,与此头设置为字符串基本用户名的值:密码,但与用户名:字符串基地64 EN $ C $光盘的密码部分。

It is possible to log in using HTTP authentication by setting the "Authorization" HTTP header, with the value of this header set to the string "basic username:password", but with the "username:password" portion of the string Base 64 encoded.

http://frontier.userland.com/stories/storyReader$2159

的研究发现,具有的GreaseMonkey一个功能内置到它,你可以发送GET / POST请求称为GM_xmlhtt $,服务器A位P $ pquest

A bit of researching found that GreaseMonkey has a a function built into it where you can send GET / POST requests to the server called GM_xmlhttpRequest

http://diveintogreasemonkey.org/api/gm_xmlhtt$p$pquest.html

所以把他们放在一起(并且也越来越这段JavaScript code将字符串转换为base64,我得到以下

So putting it all together (and also getting this JavaScript code to convert strings into base64 I get the following

http://www.webtoolkit.info/javascript-base64.html

var loggedInText = document.getElementById('metanav').firstChild.firstChild.innerHTML;
if (loggedInText != "logged in as jklp") {
    var username = 'jklp';
    var password = 'jklpPass';
    var base64string = Base64.encode(username + ":" + password);

    GM_xmlhttpRequest({
        method: 'GET',
        url: 'http://foo.com/trac/login',
        headers: {
            'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
            'Accept': 'application/atom+xml,application/xml,text/xml',
            'Authorization':'Basic ' + base64string,
        }
    });
}

所以,当我现在访问该网站,它遍历DOM,如果我没有登录,它自动地记录我进来。

So when I now visit the site, it traverses the DOM and if I'm not logged in, it automagically logs me in.

这篇关于的GreaseMonkey脚本来自动登录使用HTTP认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆